Package com.powsybl.commons.compress
Class ZipPackager
java.lang.Object
com.powsybl.commons.compress.ZipPackager
- Author:
- Yichen TANG <yichen.tang at rte-france.com>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionKey as zip entry name.If the path to file is null or not exists, the method does nothing.Key as zip entry name.Key as zip entry name.static byte[]
archiveBytesByNameToZipBytes
(Map<String, byte[]> bytesByName) Generates a zip file's bytesstatic byte[]
archiveFilesToZipBytes
(Path workingDir, String... fileNames) static byte[]
archiveFilesToZipBytes
(Path baseDir, List<String> fileNames) If the file is in .gz(detected by last 3 characters) format, the method decompresses .gz file first.byte[]
Should only be called once.
-
Constructor Details
-
ZipPackager
public ZipPackager()
-
-
Method Details
-
addPath
If the path to file is null or not exists, the method does nothing. If the file is in .gz(detected by last 3 characters) format, the method decompresses .gz file first.- Parameters:
path
- the file to add in zip bytes- Returns:
- a reference to this object
-
addPaths
- Parameters:
baseDir
- the base directory of all filesfilenames
- all files to add in zip bytes- Returns:
- a reference to this object
-
addPaths
- Parameters:
baseDir
- the base directory of all filesfilenames
- all files to add in zip bytes- Returns:
- a reference to this object
-
addString
Key as zip entry name. Both key and content must not be null.- Parameters:
key
-content
-- Returns:
- a reference to this object
-
addString
Key as zip entry name. Both key and content must not be null.- Parameters:
key
-content
-charset
- be used to encode content- Returns:
- a reference to this object
-
addBytes
Key as zip entry name. Both key and bytes must not be null.- Parameters:
key
-bytes
-- Returns:
- a reference to this object
-
toZipBytes
public byte[] toZipBytes()Should only be called once.- Returns:
- an array of zip bytes
-
archiveFilesToZipBytes
If the file is in .gz(detected by last 3 characters) format, the method decompresses .gz file first.- Parameters:
baseDir
- the base directory contaions files to zipfileNames
- the files to be added in zip- Returns:
- bytes in zip format
-
archiveFilesToZipBytes
-
archiveBytesByNameToZipBytes
Generates a zip file's bytes- Parameters:
bytesByName
- map's key as entry name, value as content in the zip file- Returns:
- a zip file in bytes
-