Package utils.common
Class ZipUtil
- java.lang.Object
-
- utils.common.ZipUtil
-
@Singleton public class ZipUtil extends java.lang.ObjectUtility class that does zipping and unzipping.
-
-
Constructor Summary
Constructors Constructor Description ZipUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddDataToZip(java.util.zip.ZipOutputStream zipOut, java.lang.String data, java.lang.String pathInZip)Writes the given data as a file to the zip stream using pathInZip as the path in the zip packagestatic voidaddDirToZip(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file)Writes a directory to the ZipOutputStream walking recursively through the file system.static voidaddFileToZip(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file)Writes the file using its filename into the ZipOutputStream under path zipRoot in the zip packagestatic voidaddFileToZip(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path zipFilename, java.nio.file.Path file)Writes the file into the ZipOutputStream under the path '/zipRoot/zipFilename'static voidaddToZip(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file)Add a path (can be a file or a directory) to a ZipOutputStream under path zipRoot in the zipstatic java.nio.file.Pathunzip(java.nio.file.Path fileToUnzip, java.nio.file.Path destDir)Unzips the given file.static voidzipFiles(java.util.List<java.nio.file.Path> filesToZip, java.nio.file.Path zipFile)Generates a zip archive file and writes a list of files into it
-
-
-
Method Detail
-
unzip
public static java.nio.file.Path unzip(java.nio.file.Path fileToUnzip, java.nio.file.Path destDir) throws java.io.IOExceptionUnzips the given file. Creates a new directory in the system's temp directory and writes the zip's content in there. The method can handle recursive unzipping of subdirectories.- Throws:
java.io.IOException
-
zipFiles
public static void zipFiles(java.util.List<java.nio.file.Path> filesToZip, java.nio.file.Path zipFile) throws java.io.IOExceptionGenerates a zip archive file and writes a list of files into it- Throws:
java.io.IOException
-
addToZip
public static void addToZip(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file) throws java.io.IOExceptionAdd a path (can be a file or a directory) to a ZipOutputStream under path zipRoot in the zip- Throws:
java.io.IOException
-
addDirToZip
public static void addDirToZip(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file) throws java.io.IOExceptionWrites a directory to the ZipOutputStream walking recursively through the file system.- Throws:
java.io.IOException
-
addFileToZip
public static void addFileToZip(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path file) throws java.io.IOExceptionWrites the file using its filename into the ZipOutputStream under path zipRoot in the zip package- Throws:
java.io.IOException
-
addFileToZip
public static void addFileToZip(java.util.zip.ZipOutputStream out, java.nio.file.Path zipRoot, java.nio.file.Path zipFilename, java.nio.file.Path file) throws java.io.IOExceptionWrites the file into the ZipOutputStream under the path '/zipRoot/zipFilename'- Throws:
java.io.IOException
-
addDataToZip
public static void addDataToZip(java.util.zip.ZipOutputStream zipOut, java.lang.String data, java.lang.String pathInZip) throws java.io.IOExceptionWrites the given data as a file to the zip stream using pathInZip as the path in the zip package- Throws:
java.io.IOException
-
-