Change character encoding and/or end of line style for a text file.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.text |
Category: | Text tasks |
Since: | 0.5 |
EntityFS-aware? | Yes* |
Implements: | ActionTaskFactory GeneratorTaskFactory ProcessTaskFactory |
See also: | RecursiveActionTF RecursiveProcessTF ReplaceSourceFileTF |
Description:
Change character encoding and/or end of line style for a text file.
Required properties
Properties
eolStyle | top |
The end of line style of the output file.
- Setter method:
setEolStyle(EolStyle eos)
parameters:eos
– The end of line style of the output file. This is one ofEolStyle.CR
– A single carriage returnEolStyle.LF
– A single linefeedEolStyle.CRLF
– A carriage return followed by a linefeedEolStyle.MAX
– Mac style (CR)EolStyle.UNIX
– Unix style (LF)EolStyle.DOS
– DOS style (CRLF)EolStyle.WIN
– Windows style (CRLF)
- Default value:
-
The value of the system property
line.separator
(platform dependent).
inputEncoding | top |
The character encoding of the input file. Use this if the input file has a non-standard encoding, i.e. an encoding different from the Java virtual machine's (platform dependent) default charset.
- Setter method:
setInputEncoding(Charset c)
parameters:c
– The input charset.- Setter method:
setInputEncoding(String s)
parameters:s
– The name of a character encoding.- Default value:
- The platform's default encoding.
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
outputEncoding | top |
The character encoding of the output file. Use this if the output file should have a non-standard encoding, i.e. an encoding different from the Java virtual machine's (platform dependent) default charset.
- Setter method:
setOutputEncoding(Charset c)
parameters:c
– The output charset.- Setter method:
setOutputEncoding(String s)
parameters:s
– The name of a character encoding.- Default value:
- The platform's default encoding.
- See also:
- target
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 text source.
- Setter method:
setSource(Object o)
parameters:- See also:
- inputEncoding
target (required) | top |
The target to store the formatted text in.
- Setter method:
setTarget(Object o)
parameters:- See also:
- outputEncoding
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
Example 1
Emulate the unix2dos
command and convert the
file foo.txt
putting the result in foo_conv.txt
. Both
files are in the directory d
.
JavaScript
Example 2
Emulate the dos2unix
command and convert all
text files in the directory hierarchy under d
, putting the new
files in a directory hierarchy under dp
.
JavaScript
Example 3
Emulate the dos2unix
command and convert all
text files in the directory hierarchy under d
, overwriting the old
files.
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.