Class ZIPTool


  • public class ZIPTool
    extends java.lang.Object
    ZIP toolbox
    This class only provides static variables and methods
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void build​(java.io.OutputStream out, java.util.Map<java.lang.String,​byte[]> files)
      Build a zip file from a map of file names and byte array contents
      static void build​(java.lang.String rootDir, java.io.OutputStream out)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use build with additional arguments
      static void build​(java.lang.String rootDir, java.io.OutputStream out, java.util.List<java.lang.String> files, java.io.File zipFile)
      Build a ZIP stream from a list of file paths
      static java.io.File build​(java.lang.String rootDir, java.lang.String zipFile, java.util.List<java.lang.String> files)
      Build a ZIP file from a list of file paths
      static byte[] build​(java.lang.String zipFile, java.util.Map<java.lang.String,​byte[]> files)
      Build a ZIP file from a map of file names and return its content as byte array
      static byte[] build​(java.util.Map<java.lang.String,​byte[]> files)
      Build a ZIP byte array from a map of file names
      static void extract​(java.io.File zipFile, java.io.File destDir)
      Extract ZIP file to folder
      static void extract​(java.io.InputStream zipData, java.io.File destDir)
      Extract ZIP file to folder
      static void extract​(java.io.InputStream zipData, java.io.File destDir, java.lang.String zipFormat)
      Extract archive to folder
      static void extract​(java.lang.String zipFilePath, java.lang.String destDir)
      Extract ZIP file to folder
      static java.io.File[] extractXMLFiles​(java.io.InputStream zipData, java.lang.String tmpdir)  
      static java.io.File[] extractXMLFiles​(java.io.InputStream zipData, java.lang.String tmpdir, java.lang.String zipFormat)
      Extract XML files
      static java.util.List<java.lang.String> list​(byte[] zipData)
      List ZIP file entries
      static java.util.List<java.lang.String> list​(java.io.File zipFile)
      List ZIP file entries
      static java.util.List<java.lang.String> list​(java.lang.String zipFilePath)
      List ZIP file entries
      static void tarGzip​(java.lang.String rootDir, java.lang.String gzipFile, java.util.List<java.lang.String> files)
      Build a tar.gz file from a list of file paths
      static void tarGzip​(java.lang.String rootDir, java.lang.String gzipFile, java.util.List<java.lang.String> files, java.util.List<java.lang.String> excludedFiles)
      Build a tar.gz file from a list of file paths
      static void tarGzipExtract​(java.io.InputStream in, java.io.File destDir)
      Extract a tar.gz archive stream
      static void tarGzipExtract​(java.lang.String file, java.lang.String destDir)
      Extract a tar.gz archive file
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • build

        @Deprecated(forRemoval=true,
                    since="4.0")
        public static void build​(java.lang.String rootDir,
                                 java.io.OutputStream out)
                          throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use build with additional arguments
        Throws:
        java.io.IOException
      • build

        public static void build​(java.lang.String rootDir,
                                 java.io.OutputStream out,
                                 java.util.List<java.lang.String> files,
                                 java.io.File zipFile)
                          throws java.io.IOException
        Build a ZIP stream from a list of file paths
        Parameters:
        rootDir - Root folder path (all file with non absolute path will be read in root folder)
        out - Output stream
        files - File paths (if null all files in folder are included)
        zipFile - Zip file to exclude if exists in rootDir
        Throws:
        java.io.IOException
      • build

        public static java.io.File build​(java.lang.String rootDir,
                                         java.lang.String zipFile,
                                         java.util.List<java.lang.String> files)
                                  throws java.io.IOException
        Build a ZIP file from a list of file paths
        Parameters:
        rootDir - Root folder path (all file with non absolute path will be read in root folder)
        zipFile - ZIP file path
        files - File paths (if null all files in folder are included)
        Returns:
        Zip file
        Throws:
        java.io.IOException
      • build

        public static void build​(java.io.OutputStream out,
                                 java.util.Map<java.lang.String,​byte[]> files)
                          throws java.io.IOException
        Build a zip file from a map of file names and byte array contents
        Parameters:
        out - ZIP output stream
        files - Map of file names and byte array contents
        Throws:
        java.io.IOException
      • build

        public static byte[] build​(java.lang.String zipFile,
                                   java.util.Map<java.lang.String,​byte[]> files)
                            throws java.io.IOException
        Build a ZIP file from a map of file names and return its content as byte array
        Parameters:
        zipFile - ZIP file path
        files - Map of file names and byte array contents
        Returns:
        ZIP byte array read from file path (note that the ZIP file is not deleted)
        Throws:
        java.io.IOException
      • build

        public static byte[] build​(java.util.Map<java.lang.String,​byte[]> files)
                            throws java.io.IOException
        Build a ZIP byte array from a map of file names
        Parameters:
        files - Map of file names and byte array contents
        Returns:
        ZIP byte array
        Throws:
        java.io.IOException
      • extract

        public static void extract​(java.io.InputStream zipData,
                                   java.io.File destDir,
                                   java.lang.String zipFormat)
                            throws java.io.IOException
        Extract archive to folder
        Parameters:
        zipData - ZIP data
        destDir - Destination folder
        zipFormat - Integration.FORMAT_ZIP or Integration.FORMAT_GZIP
        Throws:
        java.io.IOException
      • extract

        public static void extract​(java.lang.String zipFilePath,
                                   java.lang.String destDir)
                            throws java.io.IOException
        Extract ZIP file to folder
        Parameters:
        zipFilePath - ZIP file path
        destDir - Destination folder path
        Throws:
        java.io.IOException
      • extract

        public static void extract​(java.io.File zipFile,
                                   java.io.File destDir)
                            throws java.io.IOException
        Extract ZIP file to folder
        Parameters:
        zipFile - ZIP file
        destDir - Destination folder
        Throws:
        java.io.IOException
      • extract

        public static void extract​(java.io.InputStream zipData,
                                   java.io.File destDir)
                            throws java.io.IOException
        Extract ZIP file to folder
        Parameters:
        zipData - ZIP data
        destDir - Destination folder
        Throws:
        java.io.IOException
      • list

        public static java.util.List<java.lang.String> list​(java.lang.String zipFilePath)
                                                     throws java.io.IOException
        List ZIP file entries
        Parameters:
        zipFilePath - ZIP file path
        Throws:
        java.io.IOException - If list fails
      • list

        public static java.util.List<java.lang.String> list​(java.io.File zipFile)
                                                     throws java.io.IOException
        List ZIP file entries
        Parameters:
        zipFile - ZIP file
        Throws:
        java.io.IOException - If list fails
      • list

        public static java.util.List<java.lang.String> list​(byte[] zipData)
                                                     throws java.io.IOException
        List ZIP file entries
        Parameters:
        zipData - ZIP data
        Throws:
        java.io.IOException - If list fails
      • extractXMLFiles

        public static java.io.File[] extractXMLFiles​(java.io.InputStream zipData,
                                                     java.lang.String tmpdir)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • extractXMLFiles

        public static java.io.File[] extractXMLFiles​(java.io.InputStream zipData,
                                                     java.lang.String tmpdir,
                                                     java.lang.String zipFormat)
                                              throws java.io.IOException
        Extract XML files
        Parameters:
        zipData - ZIP input stream
        tmpdir - Temporary directory
        zipFormat - Integration.FORMAT_ZIP or Integration.FORMAT_GZIP
        Returns:
        Array of XML files
        Throws:
        java.io.IOException - If extraction fails
      • tarGzip

        public static void tarGzip​(java.lang.String rootDir,
                                   java.lang.String gzipFile,
                                   java.util.List<java.lang.String> files)
                            throws java.io.IOException
        Build a tar.gz file from a list of file paths
        Parameters:
        rootDir - Root folder path (all file with non absolute path will be read in root folder)
        gzipFile - Path to the tar.gz to build
        files - File paths (if null all files in folder are included)
        Throws:
        java.io.IOException
      • tarGzip

        public static void tarGzip​(java.lang.String rootDir,
                                   java.lang.String gzipFile,
                                   java.util.List<java.lang.String> files,
                                   java.util.List<java.lang.String> excludedFiles)
                            throws java.io.IOException
        Build a tar.gz file from a list of file paths
        Parameters:
        rootDir - Root folder path (all file with non absolute path will be read in root folder)
        gzipFile - Path to the tar.gz to build
        files - File paths (if null all files in folder are included)
        excludedFiles - File paths (if null all files in folder are included)
        Throws:
        java.io.IOException
      • tarGzipExtract

        public static void tarGzipExtract​(java.lang.String file,
                                          java.lang.String destDir)
                                   throws java.io.IOException
        Extract a tar.gz archive file
        Parameters:
        file - Path to the tar.gz file
        destDir - Path to destination folder
        Throws:
        java.io.IOException
      • tarGzipExtract

        public static void tarGzipExtract​(java.io.InputStream in,
                                          java.io.File destDir)
                                   throws java.io.IOException
        Extract a tar.gz archive stream
        Parameters:
        in - Archive input stream
        destDir - Destination folder
        Throws:
        java.io.IOException