ZIP resource transformers are used to manipulate the contents of the created archive. They are created by a ZipResourceTransformerFactory, and instantiated when the ZIP archive creation is started.
The resource transformers process the archive entries in a streaming way, meaning that as the entries are being written to the result archive, the transformers are presented an opportunity to examine and modify or otherwise manipulate the contents of an entry.
Resource transformers may modify the contents, write new entries, omit entries, and otherwise manipulate the created archive. They work with a ZipResourceTransformationContext that provides write access to the created ZIP.
During an archive creation, multiple resource transformers may be present. When there are multiple transformers, the processing will be done after each other. It may be the case that a resource transformer works with an already transformed entry.
The methods process, flush and end are called on a transformer in this order. The process method is called multiple times for each processed entry.
Clients should implement this interface.
public default void | end( Ends the transformation for this transformer. |
public default void | flush( Asks the processor to write any pending resources to the ZIP archive. |
public boolean | process( Deprecated since saker.zip 0.8.5. Use
process( |
public default ZipResourceEntry | process( Processes the ZIP resource specified by the arguments. |
This method is similar to flush(
Any generated resources won't be passed to
process(
After this method is called, the transformer won't be used any more.
It is generally recommended to use flush(
The default implementation does nothing.
Any written resources will be subject to further processing. Implementations should handle if
process(
The default implementation does nothing.
This method is called by the ZIP archiver to ask the transformer to process the specified resource. The transformer can either consume the resource or not.
When a resource is consumed, it will not be passed to subsequent transformers, and will not be written to the ZIP archive output.
The transformers can decide to consume the resource, and write a resource to the archive using the transformation context.
If the transformer doesn't consume the resource, subsequent transformers will be asked to process it. If no transformer consumes the resource, it will be written to the archive as is.
Implementations should take care to implement guarding when they process and generate a resource with the same name. Not employing guarding may result in infinite looping by the transformation context.
null
if the resource is a directory.true
if the resource is consumed by this transformer, and shouldn't be written to the
output. false
if the transformer doesn't consume this resource.This method is called by the ZIP archiver to ask the transformer to process the specified resource. The transformer can either consume the resource or not.
When a resource is consumed, it will not be passed to subsequent transformers, and will not be written to the ZIP archive output.
The transformers can decide to consume the resource, and write a resource to the archive using the transformation context.
If the transformer doesn't consume the resource, subsequent transformers will be asked to process it. If no transformer consumes the resource, it will be written to the archive as is.
Implementations should take care to implement guarding when they process and generate a resource with the same name. Not employing guarding may result in infinite looping by the transformation context.
Transformers are also allowed to return a different ZipResourceEntry instance from this method which
allows to change the attributes of the written resource. E.g. an implementation can use
ZipResourceEntry.withEntryPath(
If the transformer doesn't modify the resource in any way, it can simply return the argument ZipResourceEntry.
The default implementation calls the previous process method (which is already deprecated).
null
if the resource is a directory.nulolo
if the resource is consumed by this transformer, and shouldn't be written to the
output. Non-null
if the transformer doesn't consume this resource and it should be
written with the attributes from the returned entry.