Class Zips


  • public class Zips
    extends Object
    Created by tchemit on 30/12/2017.
    Author:
    Tony Chemit - dev@tchemit.fr
    • Constructor Detail

      • Zips

        public Zips()
    • Method Detail

      • uncompress

        public static void uncompress​(InputStream stream,
                                      File targetDir)
                               throws IOException
        Uncompress zipped stream in targetDir.
        Parameters:
        stream - the zip source stream, stream is closed before return
        targetDir - the destination directory
        Throws:
        IOException - if any problem while unzip
        Since:
        2.6.6
      • uncompressAndRename

        public static void uncompressAndRename​(InputStream stream,
                                               File targetDir,
                                               String renameFrom,
                                               String renameTo)
                                        throws IOException
        Uncompress zipped stream in targetDir, and rename uncompressed file if necessary. If renameFrom or renameTo is null no renaming is done

        file in zip use / to separate directory and not begin with / each directory ended with /

        Parameters:
        stream - the zip source stream, stream is closed before return
        targetDir - the destination directory
        renameFrom - pattern to permit rename file before uncompress it
        renameTo - new name for file if renameFrom is applicable to it you can use $1, $2, ... if you have '(' ')' in renameFrom
        Throws:
        IOException - if any problem while uncompressing
        Since:
        2.6.6
      • uncompressFiltred

        public static void uncompressFiltred​(File file,
                                             File targetDir,
                                             String... excludes)
                                      throws IOException
        Unzip compressed archive and keep non excluded patterns.
        Parameters:
        file - archive file
        targetDir - destination file
        excludes - excludes pattern (pattern must match complete entry name including root folder)
        Throws:
        IOException - FIXME
      • createDirectoryIfNecessary

        public static void createDirectoryIfNecessary​(File dir)
      • isZipFile

        public static boolean isZipFile​(File file)
        Tests if the given file is a zip file.
        Parameters:
        file - the file to test
        Returns:
        true if the file is a valid zip file, false otherwise.
        Since:
        2.4.9
      • compressFiles

        public static void compressFiles​(File zipFile,
                                         File root,
                                         Collection<File> includes)
                                  throws IOException
        Compress 'includes' files in zipFile. If file in includes is directory only the directory is put in zipFile, not the file contained in directory
        Parameters:
        zipFile - the destination zip file
        root - for all file in includes that is in this directory, then we remove this directory in zip entry name (aka -C for tar), can be null;
        includes - the files to include in zip
        Throws:
        IOException - if any problem while compressing