public class Zips
extends java.lang.Object
Path
based).Modifier and Type | Class and Description |
---|---|
private static class |
Zips.NoPreserveRootPathMapper |
private static class |
Zips.PackerFileVisitor |
private static interface |
Zips.PathMapper |
private static class |
Zips.PreserveRootPathMapper |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
BACKSLASH_ESCAPE_REPLACEMENT |
private static java.util.regex.Pattern |
BACKSLASH_PATTERN |
private static java.lang.String |
ZIP_ENTRY_NAME_SEPARATOR |
Constructor and Description |
---|
Zips() |
Modifier and Type | Method and Description |
---|---|
private static java.nio.file.Path |
checkPathExists(java.nio.file.Path source,
java.lang.String msg) |
private static org.apache.commons.compress.archivers.zip.ZipArchiveEntry |
createArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos,
java.lang.String entryName) |
private static java.lang.String |
entryNameFrom(java.nio.file.Path path,
boolean isDirectoryw) |
private static void |
fixPosixPermissions(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry,
java.nio.file.Path entryPath) |
private static java.io.BufferedOutputStream |
newBufferedOutputStream(java.nio.file.Path path) |
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) |
static int |
packJar(java.nio.file.Path source,
java.nio.file.Path targetJar,
boolean preserveRoot)
Zip the given
source file or folder in the targetJar Jar
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 int |
packZip(java.nio.file.Path source,
java.nio.file.Path targetZip,
boolean preserveRoot)
Zip the given
source file or folder in the targetZip Zip
file. |
private static void |
putDirectoryEntry(java.nio.file.Path dir,
org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos,
java.nio.file.Path entryPath) |
private static void |
putFileEntry(java.nio.file.Path file,
org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos,
java.nio.file.Path entryPath) |
private static void |
setPermissions(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry,
java.nio.file.Path entryPath) |
(package private) static int |
unpack(org.apache.commons.compress.archivers.tar.TarArchiveInputStream zis,
java.nio.file.Path outputDir) |
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) |
static int |
unpackJar(java.nio.file.Path source,
java.nio.file.Path outputDir)
Unzip the given
source Jar file in the outputDir . |
static int |
unpackTarGz(java.nio.file.Path sourcePath,
java.nio.file.Path outputDir) |
static int |
unpackZip(java.nio.file.Path source,
java.nio.file.Path outputDir)
Unzip the given
source Zip file in the outputDir . |
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) |
private static final java.lang.String ZIP_ENTRY_NAME_SEPARATOR
private static final java.lang.String BACKSLASH_ESCAPE_REPLACEMENT
private static final java.util.regex.Pattern BACKSLASH_PATTERN
public static int unpackZip(java.nio.file.Path source, java.nio.file.Path outputDir) throws java.io.IOException
source
Zip file in the outputDir
.source
- the file to unzip.outputDir
- the output directory where the Zip will be unpacked.java.io.IOException
private static void fixPosixPermissions(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry, java.nio.file.Path entryPath)
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
java.io.IOException
java.util.zip.ZipException
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
java.io.IOException
java.util.zip.ZipException
public static int unpackJar(java.nio.file.Path source, java.nio.file.Path outputDir) throws java.io.IOException
source
Jar file in the outputDir
.source
- the file to unzip.outputDir
- the output directory where the Jar will be unpacked. It does
not have to exist beforehand.java.io.IOException
public static int unpackTarGz(java.nio.file.Path sourcePath, java.nio.file.Path outputDir) throws java.io.IOException
java.io.IOException
static int unpack(org.apache.commons.compress.archivers.tar.TarArchiveInputStream zis, java.nio.file.Path outputDir) throws java.io.IOException
java.io.IOException
private static void setPermissions(org.apache.commons.compress.archivers.tar.TarArchiveEntry entry, java.nio.file.Path entryPath) throws java.io.IOException
java.io.IOException
public static int packZip(java.nio.file.Path source, java.nio.file.Path targetZip, boolean preserveRoot) throws java.io.IOException
source
file or folder in the targetZip
Zip
file. If preserveRoot
is set to true, the output Zip will contain
the folder and its contents, only its contents otherwise.source
- the folder to zip.targetZip
- the Zip file to create or overwrite.preserveRoot
- whether the source
folder should be kept in the target
Zip.java.io.IOException
public static int packJar(java.nio.file.Path source, java.nio.file.Path targetJar, boolean preserveRoot) throws java.io.IOException
source
file or folder in the targetJar
Jar
file. If preserveRoot
is set to true, the output Zip will contain
the folder and its contents, only its contents otherwise.source
- the folder to zip.targetJar
- the Jar file to create or overwrite.preserveRoot
- whether the source
folder should be kept in the target
Jar.java.io.IOException
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.IOException
source
- the folder to jar. If not a directory, returns 0 and do
nothingpreserveRoot
- whether the root folderjos
- the jar output stream to writejava.io.IOException
private static java.nio.file.Path checkPathExists(java.nio.file.Path source, java.lang.String msg)
private static java.io.BufferedOutputStream newBufferedOutputStream(java.nio.file.Path path) throws java.io.IOException
java.io.IOException
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
java.io.IOException
private static java.lang.String entryNameFrom(java.nio.file.Path path, boolean isDirectoryw)
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
java.io.IOException
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
java.io.IOException
private static org.apache.commons.compress.archivers.zip.ZipArchiveEntry createArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos, java.lang.String entryName)