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 class
private static final class
private static interface
private static final class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Path
checkPathExists
(Path source, String msg) private static org.apache.commons.compress.archivers.zip.ZipArchiveEntry
createArchiveEntry
(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, String entryName) private static String
entryNameFrom
(Path path, boolean isDirectoryw) private static void
fixPosixPermissions
(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, Path entryPath) private static BufferedOutputStream
newBufferedOutputStream
(Path path) private static int
packEntries
(Path source, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, boolean preserveRoot, Set<Path> pathToExcludes) static int
Zip the givensource
file or folder in thetargetJar
Jar 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 int
Zip the givensource
file or folder in thetargetZip
Zip file.private static void
putDirectoryEntry
(Path dir, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, Path entryPath) private static void
putFileEntry
(Path file, org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, Path entryPath) private static void
setPermissions
(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, Path entryPath) (package private) static int
private static int
unpack
(org.apache.commons.compress.archivers.zip.ZipFile zipFile, Path outputDir, BiConsumer<org.apache.commons.compress.archivers.zip.ZipArchiveEntry, Path> entryFixer) static int
Unzip the givensource
Jar file in theoutputDir
.static int
unpackTarGz
(Path sourcePath, Path outputDir) static int
Unzip the givensource
Zip file in theoutputDir
.private static Path
unpackZipEntry
(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 givensource
Zip 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:
IOException
ZipException
-
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:
IOException
ZipException
-
unpackJar
Unzip the givensource
Jar 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 givensource
file or folder in thetargetZip
Zip file. IfpreserveRoot
is 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 thesource
folder should be kept in the target Zip.- Returns:
- the number of packed entries
- Throws:
IOException
-
packJar
Zip the givensource
file or folder in thetargetJar
Jar file. IfpreserveRoot
is 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 thesource
folder 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)
-