Class JKZipUtility

java.lang.Object
com.jk.core.util.JKZipUtility

public class JKZipUtility extends Object
This class is a utility class used for working with ZIP archives.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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
    unzip(File file)
    This method unzips the provided file to a temporary directory.
    static void
    unzip(File file, String distination)
    This method unzips the provided file to the specified destination directory.
    static Path
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JKZipUtility

      public JKZipUtility()
  • Method Details

    • unzip

      public static void unzip(InputStream in, String destDirectory)
      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

      protected static void extractFile(ZipInputStream zipIn, String filePath) throws IOException
      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

      public static Path unzip(InputStream in)
      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

      public static void zipDirectory(String source, String distZipFile)
      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

      public static void zipDirectory(File source, File distZipFile)
      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

      public static Path unzip(File file)
      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

      public static void unzip(File file, String distination)
      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

      public 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.
      Parameters:
      source - Specifies the source directory to be zipped.
      fileName - Specifies the name of the resulting ZIP file.
      Returns:
      the created ZIP file.