Package org.silverpeas.core.util
Class ZipUtil
- java.lang.Object
-
- org.silverpeas.core.util.ZipUtil
-
public class ZipUtil extends Object
Helper to manage archive files.- Author:
- sdevolder
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
compressFile(String filePath, String zipFilePath)
Compress a file into a zip file.static long
compressPathToZip(File folderToZip, File zipFile)
Méthode compressant un dossier de façon récursive au format zip.static long
compressPathToZip(String folderToZip, String zipFile)
Méthode compressant un dossier de façon récursive au format zip.static void
compressStreamToZip(InputStream inputStream, String filePathNameToCreate, String outfilename)
Méthode permettant la création et l'organisation d'un fichier zip en lui passant directement un flux d'entréestatic Optional<String>
extract(File source, File dest)
Extract the content of an archive into a directory.static int
getNbFiles(File archive)
Indicates the number of files (not directories) inside the archive.
-
-
-
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 à compresserzipFile
- - 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 à compresserzipFile
- - 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 zipfilePathNameToCreate
- - chemin et nom du fichier porté par les données du flux dans le zipoutfilename
- - 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.
-
-