FileDocCategorySizeDatePackage
StripLineBreaks.javaAPI DocApache Ant 1.704621Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.filters

StripLineBreaks

public final class StripLineBreaks extends BaseParamFilterReader implements ChainableReader
Filter to flatten the stream to a single line. Example:
<striplinebreaks/>
Or:
<filterreader
classname="org.apache.tools.ant.filters.StripLineBreaks"/>

Fields Summary
private static final String
DEFAULT_LINE_BREAKS
Line-breaking characters. What should we do on funny IBM mainframes with odd line endings?
private static final String
LINE_BREAKS_KEY
Parameter name for the line-breaking characters parameter.
private String
lineBreaks
The characters that are recognized as line breaks.
Constructors Summary
public StripLineBreaks()
Constructor for "dummy" instances.

see
BaseFilterReader#BaseFilterReader()


               
      
        super();
    
public StripLineBreaks(Reader in)
Creates a new filtered reader.

param
in A Reader object providing the underlying stream. Must not be null.

        super(in);
    
Methods Summary
public java.io.Readerchain(java.io.Reader rdr)
Creates a new StripLineBreaks using the passed in Reader for instantiation.

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

        StripLineBreaks newFilter = new StripLineBreaks(rdr);
        newFilter.setLineBreaks(getLineBreaks());
        newFilter.setInitialized(true);
        return newFilter;
    
private java.lang.StringgetLineBreaks()
Returns the line-breaking characters as a String.

return
a String containing all the characters considered as line-breaking

        return lineBreaks;
    
private voidinitialize()
Parses the parameters to set the line-breaking characters.

        String userDefinedLineBreaks = null;
        Parameter[] params = getParameters();
        if (params != null) {
            for (int i = 0; i < params.length; i++) {
                if (LINE_BREAKS_KEY.equals(params[i].getName())) {
                    userDefinedLineBreaks = params[i].getValue();
                    break;
                }
            }
        }
        if (userDefinedLineBreaks != null) {
            lineBreaks = userDefinedLineBreaks;
        }
    
public intread()
Returns the next character in the filtered stream, only including characters not in the set of line-breaking characters.

return
the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
exception
IOException if the underlying stream throws an IOException during reading

        if (!getInitialized()) {
            initialize();
            setInitialized(true);
        }

        int ch = in.read();
        while (ch != -1) {
            if (lineBreaks.indexOf(ch) == -1) {
                break;
            } else {
                ch = in.read();
            }
        }
        return ch;
    
public voidsetLineBreaks(java.lang.String lineBreaks)
Sets the line-breaking characters.

param
lineBreaks A String containing all the characters to be considered as line-breaking.

        this.lineBreaks = lineBreaks;