FileDocCategorySizeDatePackage
BaseFilterReader.javaAPI DocApache Ant 1.706129Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.filters

BaseFilterReader

public abstract class BaseFilterReader extends FilterReader
Base class for core filter readers.

Fields Summary
private static final int
BUFFER_SIZE
Buffer size used when reading
private boolean
initialized
Have the parameters passed been interpreted?
private org.apache.tools.ant.Project
project
The Ant project this filter is part of.
Constructors Summary
public BaseFilterReader()
Constructor used by Ant's introspection mechanism. The original filter reader is only used for chaining purposes, never for filtering purposes (and indeed it would be useless for filtering purposes, as it has no real data to filter). ChainedReaderHelper uses this placeholder instance to create a chain of real filters.


                                                          
      
        super(new StringReader(""));
        FileUtils.close(this);
    
public BaseFilterReader(Reader in)
Creates a new filtered reader.

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

        super(in);
    
Methods Summary
protected final booleangetInitialized()
Returns the initialized status.

return
whether or not the filter is initialized

        return initialized;
    
protected final org.apache.tools.ant.ProjectgetProject()
Returns the project this filter is part of.

return
the project this filter is part of

        return project;
    
public final intread(char[] cbuf, int off, int len)
Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

param
cbuf Destination buffer to write characters to. Must not be null.
param
off Offset at which to start storing characters.
param
len Maximum number of characters to read.
return
the number of characters read, or -1 if the end of the stream has been reached
exception
IOException If an I/O error occurs

        for (int i = 0; i < len; i++) {
            final int ch = read();
            if (ch == -1) {
                if (i == 0) {
                    return -1;
                } else {
                    return i;
                }
            }
            cbuf[off + i] = (char) ch;
        }
        return len;
    
protected final java.lang.StringreadFully()
Reads to the end of the stream, returning the contents as a String.

return
the remaining contents of the reader, as a String
exception
IOException if the underlying reader throws one during reading

        return FileUtils.readFully(in, BUFFER_SIZE);
    
protected final java.lang.StringreadLine()
Reads a line of text ending with '\n' (or until the end of the stream). The returned String retains the '\n'.

return
the line read, or null if the end of the stream has already been reached
exception
IOException if the underlying reader throws one during reading

        int ch = in.read();

        if (ch == -1) {
            return null;
        }

        StringBuffer line = new StringBuffer();

        while (ch != -1) {
            line.append ((char) ch);
            if (ch == '\n") {
                break;
            }
            ch = in.read();
        }
        return line.toString();
    
protected final voidsetInitialized(boolean initialized)
Sets the initialized status.

param
initialized Whether or not the filter is initialized.

        this.initialized = initialized;
    
public final voidsetProject(org.apache.tools.ant.Project project)
Sets the project to work with.

param
project The project this filter is part of. Should not be null.

        this.project = project;
    
public final longskip(long n)
Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.

param
n The number of characters to skip
return
the number of characters actually skipped
exception
IllegalArgumentException If n is negative.
exception
IOException If an I/O error occurs

        if (n < 0L) {
            throw new IllegalArgumentException("skip value is negative");
        }

        for (long i = 0; i < n; i++) {
            if (read() == -1) {
                return i;
            }
        }
        return n;