public final class ZipUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static BeanByteSource |
decryptZip(BeanByteSource source,
String password)
Provides a new source that decrypts the specified source ZIP.
|
static Map<String,ArrayByteSource> |
unpackInMemory(BeanByteSource source)
Unpacks the source into memory, returning a map.
|
static void |
unpackInMemory(BeanByteSource source,
BiConsumer<String,ArrayByteSource> consumer)
Unpacks the source into memory, invoking the consumer for each entry.
|
static void |
unzip(BeanByteSource source,
Path path)
Unzips the source to a file path.
|
static Map<String,ArrayByteSource> |
unzipInMemory(BeanByteSource source)
Unzips the source into memory, returning a map.
|
static void |
unzipInMemory(BeanByteSource source,
BiConsumer<String,ArrayByteSource> consumer)
Unzips the source into memory, invoking the consumer for each entry.
|
static Optional<ArrayByteSource> |
unzipPathNameInMemory(BeanByteSource source,
String relativePathName)
Unzips a single file from the source in memory.
|
static Set<String> |
unzipPathNames(BeanByteSource source)
Unzips the source returning the file names that are contained.
|
static ArrayByteSource |
zipInMemory(List<? extends BeanByteSource> sources)
Creates a zip file from the list of files in memory.
|
public static Set<String> unzipPathNames(BeanByteSource source)
The result is a set of relative path names within the zip. Only files are returned, not folders.
source - the byte source to unzipUncheckedIOException - if an IO error occurspublic static Optional<ArrayByteSource> unzipPathNameInMemory(BeanByteSource source, String relativePathName)
Callers can use unzipPathNames(BeanByteSource) to find the available names.
The relative path name must match exactly that in the zip.
source - the byte source to unziprelativePathName - the exact relative path name that the file is stored asUncheckedIOException - if an IO error occurspublic static void unzip(BeanByteSource source, Path path)
Empty folders in the zip will not be created.
source - the byte source to unzippath - the path to unzip toUncheckedIOException - if an IO error occursSecurityException - if the path is not absolute and the calling thread cannot access system property "user.dir"public static ArrayByteSource zipInMemory(List<? extends BeanByteSource> sources)
Each source must have a file name. The output will not contain subfolders.
sources - the byte sources to zipUncheckedIOException - if an IO error occurspublic static Map<String,ArrayByteSource> unpackInMemory(BeanByteSource source)
This method loads the whole unpacked file into memory.
Where possible, unpackInMemory(BeanByteSource, BiConsumer) should be preferred
as it only loads files one at a time.
Unpacking handles ZIP, GZ and BASE64 formats based entirely on the suffix of the input file name. If the input suffix is not recognized as a packed format, the consumer is invoked with the original file.
source - the byte source to unpackUncheckedIOException - if an IO error occurspublic static void unpackInMemory(BeanByteSource source, BiConsumer<String,ArrayByteSource> consumer)
Unpacking handles ZIP, GZ and BASE64 formats based entirely on the suffix of the input file name. If the input suffix is not recognized as a packed format, the consumer is invoked with the original file. This method is not recursive.
source - the byte source to unpackconsumer - the consumer, which is passed the relative path name and content for each entryUncheckedIOException - if an IO error occurspublic static Map<String,ArrayByteSource> unzipInMemory(BeanByteSource source)
This method loads the whole unpacked file into memory.
Where possible, unzipInMemory(BeanByteSource, BiConsumer) should be preferred
as it only loads files one at a time.
Unlike unpackInMemory(BeanByteSource), this method always treats the input as a zip file.
source - the byte source to unpackUncheckedIOException - if an IO error occurspublic static void unzipInMemory(BeanByteSource source, BiConsumer<String,ArrayByteSource> consumer)
Unlike unpackInMemory(BeanByteSource, BiConsumer), this method always treats the input as a zip file.
source - the byte source to unpackconsumer - the consumer, which is passed the relative path name and content for each entryUncheckedIOException - if an IO error occurspublic static BeanByteSource decryptZip(BeanByteSource source, String password)
This returns a wrapper around the input source that provides decryption. The result is normally passed directly into one of the other methods on this class.
source - the byte source to unpackpassword - the password to decrypt the inputCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.