Class ZipUtil


  • public class ZipUtil
    extends Object
    Helper to manage archive files.
    Author:
    sdevolder
    • Method Detail

      • compressFile

        public static long compressFile​(String filePath,
                                        String zipFilePath)
                                 throws IOException
        Compress a file into a zip file.
        Parameters:
        filePath -
        zipFilePath -
        Returns:
        Throws:
        IOException
      • compressPathToZip

        public static long compressPathToZip​(String folderToZip,
                                             String zipFile)
                                      throws IOException
        Méthode compressant un dossier de façon récursive au format zip.
        Parameters:
        folderToZip - - dossier à compresser
        zipFile - - fichier zip à creer
        Returns:
        la taille du fichier zip généré en octets
        Throws:
        FileNotFoundException
        IOException
      • compressPathToZip

        public static long compressPathToZip​(File folderToZip,
                                             File zipFile)
                                      throws IOException
        Méthode compressant un dossier de façon récursive au format zip.
        Parameters:
        folderToZip - - dossier à compresser
        zipFile - - fichier zip à creer
        Returns:
        la taille du fichier zip généré en octets
        Throws:
        FileNotFoundException
        IOException
      • compressStreamToZip

        public static void compressStreamToZip​(InputStream inputStream,
                                               String filePathNameToCreate,
                                               String outfilename)
                                        throws IOException
        Méthode permettant la création et l'organisation d'un fichier zip en lui passant directement un flux d'entrée
        Parameters:
        inputStream - - flux de données à enregistrer dans le zip
        filePathNameToCreate - - chemin et nom du fichier porté par les données du flux dans le zip
        outfilename - - chemin et nom du fichier zip à creer ou compléter
        Throws:
        IOException
      • extract

        public static Optional<String> extract​(File source,
                                               File dest)
        Extract the content of an archive into a directory.
        Parameters:
        source - the archive. Must be non null.
        dest - the destination directory. Must be non null.
        Returns:
        optional encoding used, if not present an error occurred.
      • getNbFiles

        public static int getNbFiles​(File archive)
        Indicates the number of files (not directories) inside the archive.
        Parameters:
        archive - the archive whose content is analyzed.
        Returns:
        the number of files (not directories) inside the archive.