GZipTF

Compress a file using the gzip algorithm.

Task package:org.schmant.task.base
Java package:org.schmant.task.io.gzip
Category:I/O tasks
Since:0.6
EntityFS-aware?Yes*
Implements:ActionTaskFactory
GeneratorTaskFactory
ProcessTaskFactory
Produces:The interpreted target property. The exact type depends on the type used for the target.
See also:RecursiveProcessTF
BZip2TF
LzmaTF

Description:

Compress a file using the gzip algorithm.

The target property is optional if the source file is of a type that implements Named. If the target is not set, the compressed data will be written to a file with the same name as the source file plus the extension .gz.

This task uses Java's GZIPOutputStream. It does not allow the compression level to be configured. Instead it always uses zlib's default level, which currently is 6 on a scale from 1 (fastest compression) to 9 (best compression).

Note: If another task created the file to compress, it may be easier to use a GZipNewWritableFileProxy directly with that task instead instead of using a separate GZip task for the compression.

Note 2: There is no task for decompressing gzip compressed files. Use a GZipReadableFile or a GZipReadableFileProxy instead.

Required properties

Properties

bufferSizetop

The buffer size of the GZIPOutputStream used by the task.

Setter method:
setBufferSize(int size)
parameters:
size – The buffer size, in bytes.
deleteSourceFiletop

If this property is set to true, the source file will be deleted after compressing it. This requires that the source file is a Java File or an EntityFS EFile. If it is not, this task does not delete the file and logs a warning.

Setter method:
setDeleteSourceFile(boolean b)
parameters:
b – Should the source file be deleted?
logFootertop

The message that is logged to info level after the task has been successfully run.

Setter method:
setLogFooter(String s)
parameters:
s – The footer message.
Default value:
Empty (no footer message is logged.)
See also:
logHeader
logHeadertop

The message that is logged to info level before the task is run.

Setter method:
setLogHeader(String s)
parameters:
s – The header message.
Default value:
A task class specific message.
See also:
logFooter
overwriteStrategytop

The overwrite strategy decides how the task will react if there already is an entity (file or directory) in a location where it wants to create a new entity.

If the strategy is to not overwrite existing entities, the task will fail when it cannot create the entities that it wants to create.

Non-empty directories are never overwritten, regardless of the chosen strategy.

Setter method:
setOverwrite(boolean b)
Setting this to a value of true means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.
parameters:
b – Should an existing entity be overwritten?
Setter method:
setOverwriteStrategy(OverwriteStrategy strat)
Set the overwrite strategy.
parameters:
strat – The overwrite strategy.
Default value:
DontOverwriteAndThrowException
See also:
target
reportLeveltop

This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.

Setter method:
setReportLevel(Level l)
Set the report level
parameters:
l – The new report level.
source (required)top

The file to compress.

Setter method:
setSource(Object o)
parameters:
o –  The source file.
Interpreted by InterpretAsReadableFileStrategy.
target (required)top

The file that the compressed data should be put in.

Setter method:
setTarget(Object o)
Set the target.
parameters:
o – A target that can be interpreted as a writable file. If the target already exists, the overwriteStrategy property determines what will happen.
Interpreted by InterpretAsNewWritableFileStrategy.
See also:
overwriteStrategy
traceLoggingtop

If trace logging is enabled for a task, it reports its configuration before it is run.

Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).

Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.
parameters:
b – Enable trace logging?

Examples

This RecursiveActionTF example shows how several files in a directory hierarchy are gzip'ped

Example 1

Compress the file f in the Directory dir to f.gz in the same directory.

new GZipTF(). setSource(Directories.getFile(dir, "f")). setTarget(new FutureFile(dir, "f.gz")).run();

Example 2

Put some text in the gzip compressed file f.gz.

import org.entityfs.util.CharSequenceReadableFile import org.schmant.support.FutureFile import org.schmant.task.io.gzip.GZipTF new GZipTF(). setSource(new CharSequenceReadableFile( "NOTE:\n" + "=====\n" + "If you can read me, you have successfully decompressed this file.")). setTarget(new FutureFile(dir, "f.gz")).run()


* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.