Package com.jk.core.util
Class JKZipUtility
java.lang.Object
com.jk.core.util.JKZipUtility
This class is a utility class used for working with ZIP archives.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
extractFile
(ZipInputStream zipIn, String filePath) This method extracts a file from the provided ZIP input stream to the given file path.static Path
This method unzips the provided file to a temporary directory.static void
This method unzips the provided file to the specified destination directory.static Path
unzip
(InputStream in) This method unzips the provided input stream to a temporary directory.static void
unzip
(InputStream in, String destDirectory) This method unzips the provided input stream to the specified destination directory.static void
zipDirectory
(File source, File distZipFile) This method zips the contents of a directory to a ZIP file.static File
zipDirectory
(File source, String fileName) This method zips the contents of a directory to a ZIP file and returns the resulting ZIP file.static void
zipDirectory
(String source, String distZipFile) This method zips the contents of a directory to a ZIP file.protected static void
zipSubDirectory
(String basePath, File dir, ZipOutputStream zout) This method recursively zips the contents of a sub-directory into a ZIP output stream.
-
Constructor Details
-
JKZipUtility
public JKZipUtility()
-
-
Method Details
-
unzip
This method unzips the provided input stream to the specified destination directory.- Parameters:
in
- Specifies the input stream representing the ZIP archive.destDirectory
- Specifies the destination directory where the contents will be extracted.
-
extractFile
This method extracts a file from the provided ZIP input stream to the given file path.- Parameters:
zipIn
- Specifies the ZIP input stream.filePath
- Specifies the path where the extracted file should be saved.- Throws:
IOException
- if an I/O exception has occurred.
-
unzip
This method unzips the provided input stream to a temporary directory.- Parameters:
in
- Specifies the input stream representing the ZIP archive.- Returns:
- the path of the temporary directory where contents are extracted.
-
zipDirectory
This method zips the contents of a directory to a ZIP file.- Parameters:
source
- Specifies the source directory to be zipped.distZipFile
- Specifies the path of the destination ZIP file.
-
zipDirectory
This method zips the contents of a directory to a ZIP file.- Parameters:
source
- Specifies the source directory to be zipped.distZipFile
- Specifies the destination ZIP file.
-
zipSubDirectory
protected static void zipSubDirectory(String basePath, File dir, ZipOutputStream zout) throws IOException This method recursively zips the contents of a sub-directory into a ZIP output stream.- Parameters:
basePath
- Specifies the base path for the current sub-directory.dir
- Specifies the sub-directory to be zipped.zout
- Specifies the ZIP output stream.- Throws:
IOException
- if an I/O exception has occurred.
-
unzip
This method unzips the provided file to a temporary directory.- Parameters:
file
- Specifies the file to be unzipped.- Returns:
- the path of the temporary directory where contents are extracted.
-
unzip
This method unzips the provided file to the specified destination directory.- Parameters:
file
- Specifies the file to be unzipped.distination
- Specifies the destination directory where the contents will be extracted.
-
zipDirectory
This method zips the contents of a directory to a ZIP file and returns the resulting ZIP file.- Parameters:
source
- Specifies the source directory to be zipped.fileName
- Specifies the name of the resulting ZIP file.- Returns:
- the created ZIP file.
-