Fields Summary |
---|
private static final String | LINES_KEYParameter name for the number of lines to be returned. |
private static final String | SKIP_KEYParameter name for the number of lines to be skipped. |
private long | linesReadNumber of lines currently read in. |
private static final int | DEFAULT_NUM_LINESDefault number of lines to show |
private long | linesNumber of lines to be returned in the filtered stream. |
private long | skipNumber of lines to be skipped. |
private org.apache.tools.ant.util.LineTokenizer | lineTokenizerA line tokenizer |
private String | linethe current line from the input stream |
private int | linePosthe position in the current line |
Methods Summary |
---|
public java.io.Reader | chain(java.io.Reader rdr)Creates a new HeadFilter using the passed in
Reader for instantiation.
HeadFilter newFilter = new HeadFilter(rdr);
newFilter.setLines(getLines());
newFilter.setSkip(getSkip());
newFilter.setInitialized(true);
return newFilter;
|
private long | getLines()Returns the number of lines to be returned in the filtered stream.
return lines;
|
private long | getSkip()Returns the number of lines to be skipped in the filtered stream.
return skip;
|
private java.lang.String | headFilter(java.lang.String line)implements a head filter on the input stream
linesRead++;
if (skip > 0) {
if ((linesRead - 1) < skip) {
return null;
}
}
if (lines > 0) {
if (linesRead > (lines + skip)) {
return null;
}
}
return line;
|
private void | initialize()Scans the parameters list for the "lines" parameter and uses
it to set the number of lines to be returned in the filtered stream.
also scan for skip parameter.
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (LINES_KEY.equals(params[i].getName())) {
lines = new Long(params[i].getValue()).longValue();
continue;
}
if (SKIP_KEY.equals(params[i].getName())) {
skip = new Long(params[i].getValue()).longValue();
continue;
}
}
}
|
public int | read()Returns the next character in the filtered stream. If the desired
number of lines have already been read, the resulting stream is
effectively at an end. Otherwise, the next character from the
underlying stream is read and returned.
if (!getInitialized()) {
initialize();
setInitialized(true);
}
while (line == null || line.length() == 0) {
line = lineTokenizer.getToken(in);
if (line == null) {
return -1;
}
line = headFilter(line);
linePos = 0;
}
int ch = line.charAt(linePos);
linePos++;
if (linePos == line.length()) {
line = null;
}
return ch;
|
public void | setLines(long lines)Sets the number of lines to be returned in the filtered stream.
this.lines = lines;
|
public void | setSkip(long skip)Sets the number of lines to be skipped in the filtered stream.
this.skip = skip;
|