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

PrefixLines

public final class PrefixLines extends BaseParamFilterReader implements ChainableReader
Attaches a prefix to every line. Example:
<prefixlines prefix="Foo"/>
Or:
<filterreader classname="org.apache.tools.ant.filters.PrefixLines">
<param name="prefix" value="Foo"/>
</filterreader>

Fields Summary
private static final String
PREFIX_KEY
Parameter name for the prefix.
private String
prefix
The prefix to be used.
private String
queuedData
Data that must be read from, if not null.
Constructors Summary
public PrefixLines()
Constructor for "dummy" instances.

see
BaseFilterReader#BaseFilterReader()


               
      
        super();
    
public PrefixLines(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 PrefixLines filter 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

        PrefixLines newFilter = new PrefixLines(rdr);
        newFilter.setPrefix(getPrefix());
        newFilter.setInitialized(true);
        return newFilter;
    
private java.lang.StringgetPrefix()
Returns the prefix which will be added at the start of each input line.

return
the prefix which will be added at the start of each input line

        return prefix;
    
private voidinitialize()
Initializes the prefix if it is available from the parameters.

        Parameter[] params = getParameters();
        if (params != null) {
            for (int i = 0; i < params.length; i++) {
                if (PREFIX_KEY.equals(params[i].getName())) {
                    prefix = params[i].getValue();
                    break;
                }
            }
        }
    
public intread()
Returns the next character in the filtered stream. One line is read from the original input, and the prefix added. The resulting line is then used until it ends, at which point the next original line is read, etc.

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 = -1;

        if (queuedData != null && queuedData.length() == 0) {
            queuedData = null;
        }

        if (queuedData != null) {
            ch = queuedData.charAt(0);
            queuedData = queuedData.substring(1);
            if (queuedData.length() == 0) {
                queuedData = null;
            }
        } else {
            queuedData = readLine();
            if (queuedData == null) {
                ch = -1;
            } else {
                if (prefix != null) {
                    queuedData = prefix + queuedData;
                }
                return read();
            }
        }
        return ch;
    
public voidsetPrefix(java.lang.String prefix)
Sets the prefix to add at the start of each input line.

param
prefix The prefix to add at the start of each input line. May be null, in which case no prefix is added.

        this.prefix = prefix;