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 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 boolean | completedReadAheadWhether or not read-ahead been completed. |
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 |
private LinkedList | lineList |
Methods Summary |
---|
public java.io.Reader | chain(java.io.Reader rdr)Creates a new TailFilter using the passed in
Reader for instantiation.
TailFilter newFilter = new TailFilter(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 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())) {
setLines(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 read-ahead
has been completed, the next character in the buffer is returned.
Otherwise, the stream is read to the end and buffered (with the buffer
growing as necessary), then the appropriate position in the buffer is
set to read from.
if (!getInitialized()) {
initialize();
setInitialized(true);
}
while (line == null || line.length() == 0) {
line = lineTokenizer.getToken(in);
line = tailFilter(line);
if (line == null) {
return -1;
}
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;
|
private java.lang.String | tailFilter(java.lang.String line)implement a tail filter on a stream of lines.
line = null is the end of the stream.
if (!completedReadAhead) {
if (line != null) {
lineList.add(line);
if (lines == -1) {
if (lineList.size() > skip) {
return (String) lineList.removeFirst();
}
} else {
long linesToKeep = lines + (skip > 0 ? skip : 0);
if (linesToKeep < lineList.size()) {
lineList.removeFirst();
}
}
return "";
}
completedReadAhead = true;
if (skip > 0) {
for (int i = 0; i < skip; ++i) {
lineList.removeLast();
}
}
if (lines > -1) {
while (lineList.size() > lines) {
lineList.removeFirst();
}
}
}
if (lineList.size() > 0) {
return (String) lineList.removeFirst();
}
return null;
|