Package com.powsybl.commons.compress
Class ZipPackager
- java.lang.Object
-
- com.powsybl.commons.compress.ZipPackager
-
public class ZipPackager extends Object
- Author:
- Yichen TANG
-
-
Constructor Summary
Constructors Constructor Description ZipPackager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ZipPackager
addBytes(String key, byte[] bytes)
Key as zip entry name.ZipPackager
addPath(Path path)
If the path to file is null or not exists, the method does nothing.ZipPackager
addPaths(Path root, String... filenames)
ZipPackager
addPaths(Path baseDir, List<String> filenames)
ZipPackager
addString(String key, String content)
Key as zip entry name.ZipPackager
addString(String key, String content, Charset charset)
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[]
toZipBytes()
Should only be called once.
-
-
-
Method Detail
-
addPath
public ZipPackager addPath(@Nullable Path path)
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
public ZipPackager addPaths(Path baseDir, List<String> filenames)
- Parameters:
baseDir
- the base directory of all filesfilenames
- all files to add in zip bytes- Returns:
- a reference to this object
-
addPaths
public ZipPackager addPaths(Path root, String... filenames)
- Parameters:
baseDir
- the base directory of all filesfilenames
- all files to add in zip bytes- Returns:
- a reference to this object
-
addString
public ZipPackager addString(String key, String content)
Key as zip entry name. Both key and content must not be null.- Parameters:
key
-content
-- Returns:
- a reference to this object
-
addString
public ZipPackager addString(String key, String content, Charset charset)
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
public ZipPackager addBytes(String key, byte[] bytes)
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
public 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.- Parameters:
baseDir
- the base directory contaions files to zipfileNames
- the files to be added in zip- Returns:
- bytes in zip format
-
archiveFilesToZipBytes
public static byte[] archiveFilesToZipBytes(Path workingDir, String... fileNames)
-
-