Package io.ultreia.java4all.util
Class Zips
- java.lang.Object
-
- io.ultreia.java4all.util.Zips
-
public class Zips extends Object
Created by tchemit on 30/12/2017.- Author:
- Tony Chemit - dev@tchemit.fr
-
-
Constructor Summary
Constructors Constructor Description Zips()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcompressFiles(File zipFile, File root, Collection<File> includes)Compress 'includes' files in zipFile.static voidcreateDirectoryIfNecessary(File dir)static booleanisZipFile(File file)Tests if the given file is a zip file.static voiduncompress(InputStream stream, File targetDir)Uncompress zipped stream in targetDir.static voiduncompressAndRename(InputStream stream, File targetDir, String renameFrom, String renameTo)Uncompress zipped stream in targetDir, and rename uncompressed file if necessary.static voiduncompressFiltred(File file, File targetDir, String... excludes)Unzip compressed archive and keep non excluded patterns.
-
-
-
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 returntargetDir- 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 donefile in zip use / to separate directory and not begin with / each directory ended with /
- Parameters:
stream- the zip source stream, stream is closed before returntargetDir- the destination directoryrenameFrom- pattern to permit rename file before uncompress itrenameTo- 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 filetargetDir- destination fileexcludes- 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:
trueif the file is a valid zip file,falseotherwise.- 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 fileroot- 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
-
-