Class ZipUtil


  • public class ZipUtil
    extends Object
    This class is for handling with zip-files.
    Version:
    4.0
    Author:
    Marco Meschieri - LogicalDOC
    • Constructor Detail

      • ZipUtil

        public ZipUtil()
      • ZipUtil

        public ZipUtil​(String charset)
    • Method Detail

      • unzip

        public int unzip​(String zipFile,
                         String target)
                  throws IOException
        This method extracts all entries of a zip-file.
        Parameters:
        zipFile - Path of the zip-file.
        target - Path of the extracted files.
        Returns:
        Number of extracted entries
        Throws:
        IOException - Error unpacking the zip
      • unzip

        public int unzip​(InputStream zipStream,
                         String target)
                  throws IOException
        This method extracts all entries of a zip-file.
        Parameters:
        zipStream - the zip contents
        target - Path of the extracted files.
        Returns:
        Number of extracted entries
        Throws:
        IOException - Error unpacking the zip
      • unzip

        public long unzip​(InputStream input,
                          String entry,
                          File target)
                   throws IOException
        Extracts a specific entry inside a given zip stream
        Parameters:
        input - the stream of the zip file
        entry - name of the entry to extract
        target - the file where to store the entry
        Returns:
        number of written bytes
        Throws:
        IOException - Error unpacking the zip
      • unzipEntry

        public long unzipEntry​(File zipFile,
                               String entry,
                               File target)
                        throws IOException
        This method extracts a specific entry of a zip-file. https://github.com/srikanth-lingala/zip4j
        Parameters:
        zipFile - File to read inside it
        entry - The entry to be read
        target - The extracted file
        Returns:
        number of written bytes
        Throws:
        IOException - Error extracting the zip
      • getEntryBytes

        public byte[] getEntryBytes​(File zipFile,
                                    String entry)
        Read the entry inside the file zip resource.
        Parameters:
        zipFile - File to read inside it
        entry - The entry to be read
        Returns:
        The bytes of the entry
      • getEntryStream

        public InputStream getEntryStream​(File zipFile,
                                          String entry)
        Read the entry inside the file zip resource.
        Parameters:
        zipFile - File to read inside it
        entry - The entry to be read
        Returns:
        The stream of the entry
      • zipFile

        public void zipFile​(File src,
                            File dest)
        Compress a single file
        Parameters:
        src - The source file
        dest - The destination archive file
      • zipFolder

        public void zipFolder​(File inFolder,
                              File outFile)
        Zips a folder into a .zip archive
        Parameters:
        inFolder - the folder to compress
        outFile - the zip file
      • getFileNameCharset

        public String getFileNameCharset()
      • setFileNameCharset

        public void setFileNameCharset​(String fileNameCharset)
      • unGZipUnTar

        public void unGZipUnTar​(File tarGzFile,
                                File targetDir)
                         throws IOException
        Gunzips and Untars a given .tar.gz file
        Parameters:
        tarGzFile - the .tar.gz file
        targetDir - the target folder to unpack to
        Throws:
        IOException - An error processing the GZip or Tar
      • unGZip

        public long unGZip​(File gzFile,
                           File targetFile)
                    throws IOException
        UnGunzips a given .gz file
        Parameters:
        gzFile - the .gz file
        targetFile - the target file to unpack to
        Returns:
        size of the written file
        Throws:
        IOException - Error processing the GZip
      • unGZip

        public long unGZip​(InputStream is,
                           File target)
                    throws IOException
        UnGunzips a given .gz stream
        Parameters:
        is - the .gz stream
        target - the target file to unpack to
        Returns:
        size of the written file
        Throws:
        IOException - Error processing the GZip