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
bufferSize | top |
The buffer size of the GZIPOutputStream used by the task.
- Setter method:
setBufferSize(int size)
parameters:size
– The buffer size, in bytes.
deleteSourceFile | top |
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?
logFooter | top |
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
logHeader | top |
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
overwriteStrategy | top |
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 ofparameters:true
means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.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
reportLevel | top |
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 levelparameters:l
– The new report level.
source (required) | top |
The file to compress.
- Setter method:
setSource(Object o)
parameters:
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 byInterpretAsNewWritableFileStrategy
.- See also:
- overwriteStrategy
traceLogging | top |
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'pedExample 1
Compress the file f
in the Directory
dir
to f.gz
in the same directory.
JavaScript
JRuby
Example 2
Put some text in the gzip compressed file
f.gz
.
Groovy
JavaScript
* 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.