Top Description Inners Fields Constructors Methods
org.apache.tools.ant.filters

public final Class FixCrLfFilter

extends BaseParamFilterReader
implements ChainableReader
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.filters.ChainableReader
Imports
java.io.IOException, .Reader, org.apache.tools.ant.BuildException, org.apache.tools.ant.taskdefs.condition.Os, org.apache.tools.ant.types.EnumeratedAttribute

Converts text to local OS formatting conventions, as well as repair text damaged by misconfigured or misguided editors or file transfer programs.

This filter can take the following arguments:

None of which are required.

This version generalises the handling of EOL characters, and allows for CR-only line endings (the standard on Mac systems prior to OS X). Tab handling has also been generalised to accommodate any tabwidth from 2 to 80, inclusive. Importantly, it can leave untouched any literal TAB characters embedded within Java string or character constants.

Caution: run with care on carefully formatted files. This may sound obvious, but if you don't specify asis, presume that your files are going to be modified. If "tabs" is "add" or "remove", whitespace characters may be added or removed as necessary. Similarly, for EOLs, eol="asis" actually means convert to your native O/S EOL convention while eol="crlf" or cr="add" can result in CR characters being removed in one special case accommodated, i.e., CRCRLF is regarded as a single EOL to handle cases where other programs have converted CRLF into CRCRLF.

Example:

 <<fixcrlf tab="add" eol="crlf" eof="asis"/>
 
Or:
 <filterreader classname="org.apache.tools.ant.filters.FixCrLfFilter">
   <param eol="crlf" tab="asis"/>
  </filterreader>
 

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
FixCrLfFilter.AddAsisRemove

Enumerated attribute with the values "asis", "add" and "remove".

private static class
private static class
public static class
FixCrLfFilter.CrLf

Enumerated attribute with the values "asis", "cr", "lf" and "crlf".

private static class
private static class
private static class
private static class
private static class
FixCrLfFilter.SimpleFilterReader

This filter reader redirects all read I/O methods through its own read() method.

Field Summary

Modifier and TypeField and Description
private static final char
private FixCrLfFilter.AddAsisRemove
private static final int
private FixCrLfFilter.CrLf
private boolean
private boolean
private boolean
private static final int
private static final int
private int
private FixCrLfFilter.AddAsisRemove

Constructor Summary

AccessConstructor and Description
public
FixCrLfFilter()

Constructor for "dummy" instances.

public
FixCrLfFilter(final Reader
A Reader object providing the underlying stream. Must not be null.
in
)

Create a new filtered reader.

Method Summary

Modifier and TypeMethod and Description
private static String
public Reader

Returns:

a new filter based on this configuration, but filtering the specified reader.
chain
(final Reader
A Reader object providing the underlying stream. Must not be null.
rdr
)

Implements org.apache.tools.ant.filters.ChainableReader.chain.

Create a new FixCrLfFilter using the passed in Reader for instantiation.
public FixCrLfFilter.AddAsisRemove

Returns:

values:
  • add: ensure that there is an eof at the end of the file
  • asis: leave eof characters alone
  • remove: remove any eof character found at the end
getEof
()

Get how DOS EOF (control-z) characters are being handled.

public FixCrLfFilter.CrLf

Returns:

values:
  • asis: convert line endings to your O/S convention
  • cr: convert line endings to CR
  • lf: convert line endings to LF
  • crlf: convert line endings to CRLF
getEol
()

Get how EndOfLine characters are being handled.

public boolean

Returns:

true if a filtered file will always end with an EOL
getFixlast
()

Get whether a missing EOL be added to the final line of the stream.

public boolean

Returns:

true if whitespace in Java character and string literals is ignored.
getJavafiles
()

Get whether the stream is to be treated as though it contains Java source.

public FixCrLfFilter.AddAsisRemove

Returns:

values:
  • add: convert sequences of spaces which span a tab stop to tabs
  • asis: leave tab and space characters alone
  • remove: convert tabs to spaces
getTab
()

Return how tab characters are being handled.

public int

Returns:

the length of tab in spaces
getTablength
()

Get the tab length to use.

private void
initInternalFilters()

Wrap the input stream with the internal filters necessary to perform the configuration settings.

public synchronized int

Returns:

the next character in the resulting stream, or -1 if the end of the resulting stream has been reached.
read
()

Overrides java.io.FilterReader.read.

Return the next character in the filtered stream.
public void
setEof(FixCrLfFilter.AddAsisRemove
valid values:
  • add: ensure that there is an eof at the end of the file
  • asis: leave eof characters alone
  • remove: remove any eof character found at the end
attr
)

Specify how DOS EOF (control-z) characters are to be handled.

public void
setEol(FixCrLfFilter.CrLf
valid values:
  • asis: convert line endings to your O/S convention
  • cr: convert line endings to CR
  • lf: convert line endings to LF
  • crlf: convert line endings to CRLF
attr
)

Specify how end of line (EOL) characters are to be handled.

public void
setFixlast(boolean
if true a missing EOL will be appended.
fixlast
)

Specify whether a missing EOL will be added to the final line of input.

public void
setJavafiles(boolean
set to true to prevent this filter from changing tabs found in Java literals.
javafiles
)

Indicate whether this stream contains Java source.

public void
setTab(FixCrLfFilter.AddAsisRemove
valid values:
  • add: convert sequences of spaces which span a tab stop to tabs
  • asis: leave tab and space characters alone
  • remove: convert tabs to spaces
attr
)

Specify how tab characters are to be handled.

public void
setTablength(int
specify the length of tab in spaces. Valid values are between 2 and 80 inclusive. The default for this parameter is 8.
tabLength
)

Specify tab length in characters.

Inherited from org.apache.tools.ant.filters.BaseParamFilterReader:
getParameterssetParameters