Package org.eclipse.cbi.common.util
Class Zips
java.lang.Object
org.eclipse.cbi.common.util.Zips
Utility class to work with Zip files (
Path based).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static final classprivate static interfaceprivate static final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static PathcheckPathExists(Path source, String msg) private static org.apache.commons.compress.archivers.zip.ZipArchiveEntrycreateArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, String entryName) private static StringentryNameFrom(Path path, boolean isDirectoryw) private static voidfixPosixPermissions(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, Path entryPath) private static BufferedOutputStreamnewBufferedOutputStream(Path path) private static intpackEntries(Path source, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, boolean preserveRoot, Set<Path> pathToExcludes) static intZip the givensourcefile or folder in thetargetJarJar file.packManifestIfAny(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 intZip the givensourcefile or folder in thetargetZipZip file.private static voidputDirectoryEntry(Path dir, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, Path entryPath) private static voidputFileEntry(Path file, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, Path entryPath) private static voidsetPermissions(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, Path entryPath) (package private) static intprivate static intunpack(org.apache.commons.compress.archivers.zip.ZipFile zipFile, Path outputDir, BiConsumer<org.apache.commons.compress.archivers.zip.ZipArchiveEntry, Path> entryFixer) static intUnzip the givensourceJar file in theoutputDir.static intunpackTarGz(Path sourcePath, Path outputDir) static intUnzip the givensourceZip file in theoutputDir.private static PathunpackZipEntry(org.apache.commons.compress.archivers.zip.ZipFile zipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, Path outputDir)
-
Field Details
-
ZIP_ENTRY_NAME_SEPARATOR
- See Also:
-
BACKSLASH_ESCAPE_REPLACEMENT
- See Also:
-
BACKSLASH_PATTERN
-
-
Constructor Details
-
Zips
public Zips()
-
-
Method Details
-
unpackZip
Unzip 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:
IOException
-
fixPosixPermissions
private static void fixPosixPermissions(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, Path entryPath) -
unpack
private static int unpack(org.apache.commons.compress.archivers.zip.ZipFile zipFile, Path outputDir, BiConsumer<org.apache.commons.compress.archivers.zip.ZipArchiveEntry, Path> entryFixer) throws IOException, ZipException- Throws:
IOExceptionZipException
-
unpackZipEntry
private static Path unpackZipEntry(org.apache.commons.compress.archivers.zip.ZipFile zipFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, Path outputDir) throws IOException, ZipException - Throws:
IOExceptionZipException
-
unpackJar
Unzip 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:
IOException
-
unpackTarGz
- Throws:
IOException
-
unpack
static int unpack(org.apache.commons.compress.archivers.tar.TarArchiveInputStream zis, Path outputDir) throws IOException - Throws:
IOException
-
setPermissions
private static void setPermissions(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, Path entryPath) throws IOException - Throws:
IOException
-
packZip
Zip 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:
IOException
-
packJar
Zip 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:
IOException
-
packManifestIfAny
private static Set<Path> packManifestIfAny(Path source, org.apache.commons.compress.archivers.jar.JarArchiveOutputStream jos) throws IOException Looks 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 nothingjos- the jar output stream to writepreserveRoot- whether the root folder- Returns:
- set of paths to the META-INF and MANIFEST.MF, empty set otherwise.
- Throws:
IOException
-
checkPathExists
-
newBufferedOutputStream
- Throws:
IOException
-
packEntries
private static int packEntries(Path source, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, boolean preserveRoot, Set<Path> pathToExcludes) throws IOException - Throws:
IOException
-
entryNameFrom
-
putFileEntry
private static void putFileEntry(Path file, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, Path entryPath) throws IOException - Throws:
IOException
-
putDirectoryEntry
private static void putDirectoryEntry(Path dir, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, Path entryPath) throws IOException - Throws:
IOException
-
createArchiveEntry
private static org.apache.commons.compress.archivers.zip.ZipArchiveEntry createArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, String entryName)
-