Package org.eclipse.cbi.common.util
Class Zips
- java.lang.Object
-
- org.eclipse.cbi.common.util.Zips
-
public class Zips extends java.lang.ObjectUtility class to work with Zip files (Pathbased).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classZips.NoPreserveRootPathMapperprivate static classZips.PackerFileVisitorprivate static interfaceZips.PathMapperprivate static classZips.PreserveRootPathMapper
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringBACKSLASH_ESCAPE_REPLACEMENTprivate static java.util.regex.PatternBACKSLASH_PATTERNprivate static java.lang.StringZIP_ENTRY_NAME_SEPARATOR
-
Constructor Summary
Constructors Constructor Description Zips()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.nio.file.PathcheckPathExists(java.nio.file.Path source, java.lang.String msg)private static org.apache.commons.compress.archivers.zip.ZipArchiveEntrycreateArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, java.lang.String entryName)private static java.lang.StringentryNameFrom(java.nio.file.Path path, boolean isDirectoryw)private static voidfixPosixPermissions(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, java.nio.file.Path entryPath)private static java.io.BufferedOutputStreamnewBufferedOutputStream(java.nio.file.Path path)private static intpackEntries(java.nio.file.Path source, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, boolean preserveRoot, java.util.Set<java.nio.file.Path> pathToExcludes)static intpackJar(java.nio.file.Path source, java.nio.file.Path targetJar, boolean preserveRoot)Zip the givensourcefile or folder in thetargetJarJar file.private static java.util.Set<java.nio.file.Path>packManifestIfAny(java.nio.file.Path source, org.apache.commons.compress.archivers.jar.JarArchiveOutputStream jos)Looks for META-INF/MANIFEST.MF file in the given source folder and add them as entries to the JarOutputStream.static intpackZip(java.nio.file.Path source, java.nio.file.Path targetZip, boolean preserveRoot)Zip the givensourcefile or folder in thetargetZipZip file.private static voidputDirectoryEntry(java.nio.file.Path dir, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, java.nio.file.Path entryPath)private static voidputFileEntry(java.nio.file.Path file, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, java.nio.file.Path entryPath)private static voidsetPermissions(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, java.nio.file.Path entryPath)(package private) static intunpack(org.apache.commons.compress.archivers.tar.TarArchiveInputStream zis, java.nio.file.Path outputDir)private static intunpack(org.apache.commons.compress.archivers.zip.ZipFile zipFile, java.nio.file.Path outputDir, java.util.function.BiConsumer<org.apache.commons.compress.archivers.zip.ZipArchiveEntry,java.nio.file.Path> entryFixer)static intunpackJar(java.nio.file.Path source, java.nio.file.Path outputDir)Unzip the givensourceJar file in theoutputDir.static intunpackTarGz(java.nio.file.Path sourcePath, java.nio.file.Path outputDir)static intunpackZip(java.nio.file.Path source, java.nio.file.Path outputDir)Unzip the givensourceZip file in theoutputDir.private static java.nio.file.PathunpackZipEntry(org.apache.commons.compress.archivers.zip.ZipFile zipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, java.nio.file.Path outputDir)
-
-
-
Field Detail
-
ZIP_ENTRY_NAME_SEPARATOR
private static final java.lang.String ZIP_ENTRY_NAME_SEPARATOR
- See Also:
- Constant Field Values
-
BACKSLASH_ESCAPE_REPLACEMENT
private static final java.lang.String BACKSLASH_ESCAPE_REPLACEMENT
- See Also:
- Constant Field Values
-
BACKSLASH_PATTERN
private static final java.util.regex.Pattern BACKSLASH_PATTERN
-
-
Method Detail
-
unpackZip
public static int unpackZip(java.nio.file.Path source, java.nio.file.Path outputDir) throws java.io.IOExceptionUnzip the givensourceZip file in theoutputDir.- Parameters:
source- the file to unzip.outputDir- the output directory where the Zip will be unpacked.- Returns:
- the number of unpacked entries
- Throws:
java.io.IOException
-
fixPosixPermissions
private static void fixPosixPermissions(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, java.nio.file.Path entryPath)
-
unpack
private static int unpack(org.apache.commons.compress.archivers.zip.ZipFile zipFile, java.nio.file.Path outputDir, java.util.function.BiConsumer<org.apache.commons.compress.archivers.zip.ZipArchiveEntry,java.nio.file.Path> entryFixer) throws java.io.IOException, java.util.zip.ZipException- Throws:
java.io.IOExceptionjava.util.zip.ZipException
-
unpackZipEntry
private static java.nio.file.Path unpackZipEntry(org.apache.commons.compress.archivers.zip.ZipFile zipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, java.nio.file.Path outputDir) throws java.io.IOException, java.util.zip.ZipException- Throws:
java.io.IOExceptionjava.util.zip.ZipException
-
unpackJar
public static int unpackJar(java.nio.file.Path source, java.nio.file.Path outputDir) throws java.io.IOExceptionUnzip the givensourceJar file in theoutputDir.- Parameters:
source- the file to unzip.outputDir- the output directory where the Jar will be unpacked. It does not have to exist beforehand.- Returns:
- the number of unpacked entries
- Throws:
java.io.IOException
-
unpackTarGz
public static int unpackTarGz(java.nio.file.Path sourcePath, java.nio.file.Path outputDir) throws java.io.IOException- Throws:
java.io.IOException
-
unpack
static int unpack(org.apache.commons.compress.archivers.tar.TarArchiveInputStream zis, java.nio.file.Path outputDir) throws java.io.IOException- Throws:
java.io.IOException
-
setPermissions
private static void setPermissions(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, java.nio.file.Path entryPath) throws java.io.IOException- Throws:
java.io.IOException
-
packZip
public static int packZip(java.nio.file.Path source, java.nio.file.Path targetZip, boolean preserveRoot) throws java.io.IOExceptionZip the givensourcefile or folder in thetargetZipZip file. IfpreserveRootis set to true, the output Zip will contain the folder and its contents, only its contents otherwise.- Parameters:
source- the folder to zip.targetZip- the Zip file to create or overwrite.preserveRoot- whether thesourcefolder should be kept in the target Zip.- Returns:
- the number of packed entries
- Throws:
java.io.IOException
-
packJar
public static int packJar(java.nio.file.Path source, java.nio.file.Path targetJar, boolean preserveRoot) throws java.io.IOExceptionZip the givensourcefile or folder in thetargetJarJar file. IfpreserveRootis set to true, the output Zip will contain the folder and its contents, only its contents otherwise.- Parameters:
source- the folder to zip.targetJar- the Jar file to create or overwrite.preserveRoot- whether thesourcefolder should be kept in the target Jar.- Returns:
- the number of packed entries
- Throws:
java.io.IOException
-
packManifestIfAny
private static java.util.Set<java.nio.file.Path> packManifestIfAny(java.nio.file.Path source, org.apache.commons.compress.archivers.jar.JarArchiveOutputStream jos) throws java.io.IOExceptionLooks for META-INF/MANIFEST.MF file in the given source folder and add them as entries to the JarOutputStream.- Parameters:
source- the folder to jar. If not a directory, returns 0 and do nothingpreserveRoot- whether the root folderjos- the jar output stream to write- Returns:
- set of paths to the META-INF and MANIFEST.MF, empty set otherwise.
- Throws:
java.io.IOException
-
checkPathExists
private static java.nio.file.Path checkPathExists(java.nio.file.Path source, java.lang.String msg)
-
newBufferedOutputStream
private static java.io.BufferedOutputStream newBufferedOutputStream(java.nio.file.Path path) throws java.io.IOException- Throws:
java.io.IOException
-
packEntries
private static int packEntries(java.nio.file.Path source, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, boolean preserveRoot, java.util.Set<java.nio.file.Path> pathToExcludes) throws java.io.IOException- Throws:
java.io.IOException
-
entryNameFrom
private static java.lang.String entryNameFrom(java.nio.file.Path path, boolean isDirectoryw)
-
putFileEntry
private static void putFileEntry(java.nio.file.Path file, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, java.nio.file.Path entryPath) throws java.io.IOException- Throws:
java.io.IOException
-
putDirectoryEntry
private static void putDirectoryEntry(java.nio.file.Path dir, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, java.nio.file.Path entryPath) throws java.io.IOException- Throws:
java.io.IOException
-
createArchiveEntry
private static org.apache.commons.compress.archivers.zip.ZipArchiveEntry createArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, java.lang.String entryName)
-
-