Class ZipUtil

java.lang.Object
com.logicaldoc.util.io.ZipUtil
All Implemented Interfaces:
Closeable, AutoCloseable

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

    • ZipUtil

      public ZipUtil()
    • ZipUtil

      public ZipUtil(String charset)
  • Method Details

    • listZipEntries

      public List<ZipEntry> listZipEntries(File zipFile)
    • listEntries

      public List<String> listEntries(File zipFile)
    • unzip

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

      public int unzip(InputStream zipStream, File target) throws IOException
      This method extracts all entries of a zip-file.
      Parameters:
      zipStream - the zip contents
      target - the target folder
      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
    • unzip

      public long unzip(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
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getEntryContent

      public String getEntryContent(File zip, String entry) throws IOException
      Throws:
      IOException
    • addEntry

      public static void addEntry(File zip, String entry, InputStream content)
    • 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