Package org.zeroturnaround.zip
Class Zips
java.lang.Object
org.zeroturnaround.zip.Zips
Fluent api for zip handling.
- Author:
- shelajev
-
Method Summary
Modifier and TypeMethodDescriptionaddEntries(ZipEntrySource[] entries) Specifies entries to add or change to the output when this Zips executes.addEntry(ZipEntrySource entry) Specifies an entry to add or change to the output when this Zips executes.Adds a file entry.Adds a file entry.addFile(File file, boolean preserveRoot, FileFilter filter) Adds a file entry.addFile(File file, FileFilter filter) Adds a file entry.addTransformer(String path, ZipEntryTransformer transformer) Registers a transformer for a given entry.Specifies charset for this Zips executionbooleancontainsEntry(String name) Alias to ZipUtil.containsEntry()static Zipscreate()Static factory method to obtain an instance of Zips without source file.destination(File destination) Specifies destination file for this Zips execution, if destination is null (default value), then source file will be overwritten.static ZipsStatic factory method to obtain an instance of Zips.byte[]Alias to ZipUtil.getEntry()voiditerate(ZipEntryCallback zipEntryCallback) Reads the source ZIP file and executes the given callback for each entry.voiditerate(ZipInfoCallback callback) Scans the source ZIP file and executes the given callback for each entry.nameMapper(NameMapper nameMapper) Enables timestamp preserving for this Zips executionvoidprocess()Iterates through source Zip entries removing or changing them according to set parameters.removeEntries(String[] entries) Specifies entries to remove to the output when this Zips executes.removeEntry(String entry) Specifies an entry to remove to the output when this Zips executes.setPreserveTimestamps(boolean preserve) Specifies timestamp preserving for this Zips executionunpack()
-
Method Details
-
get
Static factory method to obtain an instance of Zips.- Parameters:
src- zip file to process- Returns:
- instance of Zips
-
create
Static factory method to obtain an instance of Zips without source file. Seeget(File src).- Returns:
- instance of Zips
-
addEntry
Specifies an entry to add or change to the output when this Zips executes. Adding takes precedence over removal of entries.- Parameters:
entry- entry to add- Returns:
- this Zips for fluent api
-
addEntries
Specifies entries to add or change to the output when this Zips executes. Adding takes precedence over removal of entries.- Parameters:
entries- entries to add- Returns:
- this Zips for fluent api
-
addFile
Adds a file entry. If given file is a dir, adds it and all subfiles recursively. Adding takes precedence over removal of entries.- Parameters:
file- file to add.- Returns:
- this Zips for fluent api
-
addFile
Adds a file entry. If given file is a dir, adds it and all subfiles recursively. Adding takes precedence over removal of entries.- Parameters:
file- file to add.preserveRoot- if file is a directory, true indicates we want to preserve this dir in the zip. otherwise children of the file are added directly under root.- Returns:
- this Zips for fluent api
-
addFile
Adds a file entry. If given file is a dir, adds it and all subfiles recursively. Adding takes precedence over removal of entries.- Parameters:
file- file to add.filter- a filter to accept files for adding, null means all files are accepted- Returns:
- this Zips for fluent api
-
addFile
Adds a file entry. If given file is a dir, adds it and all subfiles recursively. Adding takes precedence over removal of entries.- Parameters:
file- file to add.preserveRoot- if file is a directory, true indicates we want to preserve this dir in the zip. otherwise children of the file are added directly under root.filter- a filter to accept files for adding, null means all files are accepted- Returns:
- this Zips for fluent api
-
removeEntry
Specifies an entry to remove to the output when this Zips executes.- Parameters:
entry- path of the entry to remove- Returns:
- this Zips for fluent api
-
removeEntries
Specifies entries to remove to the output when this Zips executes.- Parameters:
entries- paths of the entry to remove- Returns:
- this Zips for fluent api
-
preserveTimestamps
Enables timestamp preserving for this Zips execution- Returns:
- this Zips for fluent api
-
setPreserveTimestamps
Specifies timestamp preserving for this Zips execution- Parameters:
preserve- flag to preserve timestamps- Returns:
- this Zips for fluent api
-
charset
Specifies charset for this Zips execution- Parameters:
charset- charset to use- Returns:
- this Zips for fluent api
-
destination
Specifies destination file for this Zips execution, if destination is null (default value), then source file will be overwritten. Temporary file will be used as destination and then written over the source to create an illusion if inplace action.- Parameters:
destination- charset to use- Returns:
- this Zips for fluent api
-
nameMapper
- Parameters:
nameMapper- to use when processing entries- Returns:
- this Zips for fluent api
-
unpack
-
addTransformer
Registers a transformer for a given entry.- Parameters:
path- entry to transformtransformer- transformer for the entry- Returns:
- this Zips for fluent api
-
process
public void process()Iterates through source Zip entries removing or changing them according to set parameters. -
iterate
Reads the source ZIP file and executes the given callback for each entry.For each entry the corresponding input stream is also passed to the callback. If you want to stop the loop then throw a ZipBreakException. This method is charset aware and uses Zips.charset.
- Parameters:
zipEntryCallback- callback to be called for each entry.- See Also:
-
iterate
Scans the source ZIP file and executes the given callback for each entry.Only the meta-data without the actual data is read. If you want to stop the loop then throw a ZipBreakException. This method is charset aware and uses Zips.charset.
- Parameters:
callback- callback to be called for each entry.- See Also:
-
getEntry
Alias to ZipUtil.getEntry()- Parameters:
name- name of the entry to fetch bytes from- Returns:
- byte[] contents of the entry by given name
-
containsEntry
Alias to ZipUtil.containsEntry()- Parameters:
name- entry to check existence of- Returns:
- true if zip archive we're processing contains entry by given name, false otherwise
-