saker.zip Documentation TaskDoc JavaDoc Packages
public interface ZipResourceTransformer
A streaming ZIP archive resource transformer interface.

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.

Methods
public default void
Ends the transformation for this transformer.
public default void
Asks the processor to write any pending resources to the ZIP archive.
public boolean
process(ZipResourceTransformationContext context, SakerPath resourcepath, InputStream resourceinput)
Deprecated since saker.zip 0.8.5. Use process(ZipResourceTransformationContext, ZipResourceEntry, InputStream) instead, which gives access to additional properties of the transformed resource. This function is no longer used by the ZIP creator implementation after (and including) version 0.8.5.
public default ZipResourceEntry
Processes the ZIP resource specified by the arguments.
public default void end(ZipResourceTransformationContext context) throws IOException
Ends the transformation for this transformer.

This method is similar to flush(ZipResourceTransformationContext), however, this transformer won't be called for any more resource transformations.

Any generated resources won't be passed to process(ZipResourceTransformationContext, SakerPath, InputStream), however, they will be processed by subsequent transformers.

After this method is called, the transformer won't be used any more.

It is generally recommended to use flush(ZipResourceTransformationContext) for end-of-transformation resource generation.

The default implementation does nothing.

contextThe transformation context.
IOExceptionTransformers may throw in case of errors.
public default void flush(ZipResourceTransformationContext context) throws IOException
Asks the processor to write any pending resources to the ZIP archive.

Any written resources will be subject to further processing. Implementations should handle if process(ZipResourceTransformationContext, SakerPath, InputStream) is called after this function being called.

The default implementation does nothing.

contextThe transformation context.
IOExceptionTransformers may throw in case of errors.
public abstract boolean process(ZipResourceTransformationContext context, SakerPath resourcepath, InputStream resourceinput) throws IOException
Deprecated since saker.zip 0.8.5. Use process(ZipResourceTransformationContext, ZipResourceEntry, InputStream) instead, which gives access to additional properties of the transformed resource. This function is no longer used by the ZIP creator implementation after (and including) version 0.8.5.
Processes the ZIP resource specified by the arguments.

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.

contextThe transformation context.
resourcepathThe path of the resource in the archive.
resourceinputThe input stream to the resource bytes, or 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.
IOExceptionTransformers may throw in case of errors.
public default ZipResourceEntry process(ZipResourceTransformationContext context, ZipResourceEntry resourceentry, InputStream resourceinput) throws IOException
Processes the ZIP resource specified by the arguments.

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(SakerPath) to change the entry path of the resource and return this new instance.

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).

contextThe transformation context.
resourceentryThe ZIP resource entry describing the data.
resourceinputThe input stream to the resource bytes, or 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.
IOExceptionTransformers may throw in case of errors.
saker.zip 0.8.5