Top Description Fields Constructors Methods
org.apache.tools.ant.filters

public final Class TailFilter

extends BaseParamFilterReader
implements ChainableReader
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.filters.ChainableReader
Imports
java.io.IOException, .Reader, java.util.LinkedList, org.apache.tools.ant.types.Parameter, org.apache.tools.ant.util.LineTokenizer

Reads the last n lines of a stream. (Default is last10 lines.) Example:
<tailfilter lines="3"/>
Or:
<filterreader classname="org.apache.tools.ant.filters.TailFilter">
  <param name="lines" value="3"/>
</filterreader>

Field Summary

Modifier and TypeField and Description
private boolean
completedReadAhead

Whether or not read-ahead been completed.

private static final int
DEFAULT_NUM_LINES

Default number of lines to show

private String
line

the current line from the input stream

private LinkedList<String>
private int
linePos

the position in the current line

private long
lines

Number of lines to be returned in the filtered stream.

private static final String
LINES_KEY

Parameter name for the number of lines to be returned.

private LineTokenizer
lineTokenizer

A line tokenizer

private long
skip

Number of lines to be skipped.

private static final String
SKIP_KEY

Parameter name for the number of lines to be skipped.

Constructor Summary

AccessConstructor and Description
public
TailFilter()

Constructor for "dummy" instances.

public
TailFilter(final Reader
A Reader object providing the underlying stream. Must not be null.
in
)

Creates a new filtered reader.

Method Summary

Modifier and TypeMethod and Description
public Reader

Returns:

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

Implements org.apache.tools.ant.filters.ChainableReader.chain.

Creates a new TailFilter using the passed in Reader for instantiation.
private long

Returns:

the number of lines to be returned in the filtered stream
getLines
()

Returns the number of lines to be returned in the filtered stream.

private long

Returns:

the number of lines to be skipped in the filtered stream
getSkip
()

Returns the number of lines to be skipped in the filtered stream.

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.

public int

Returns:

the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
read
()

Overrides java.io.FilterReader.read.

Returns the next character in the filtered stream.
public void
setLines(final long
the number of lines to be returned in the filtered stream
lines
)

Sets the number of lines to be returned in the filtered stream.

public void
setSkip(final long
the number of lines to be skipped in the filtered stream
skip
)

Sets the number of lines to be skipped in the filtered stream.

private String

Returns:

"" while reading in the lines, line while outputting the lines null at the end of outputting the lines
tailFilter
(String line)

implement a tail filter on a stream of lines.

Inherited from org.apache.tools.ant.filters.BaseParamFilterReader:
getParameterssetParameters

Field Detail

completedReadAheadback to summary
private boolean completedReadAhead

Whether or not read-ahead been completed.

DEFAULT_NUM_LINESback to summary
private static final int DEFAULT_NUM_LINES

Default number of lines to show

lineback to summary
private String line

the current line from the input stream

lineListback to summary
private LinkedList<String> lineList
linePosback to summary
private int linePos

the position in the current line

linesback to summary
private long lines

Number of lines to be returned in the filtered stream.

LINES_KEYback to summary
private static final String LINES_KEY

Parameter name for the number of lines to be returned.

lineTokenizerback to summary
private LineTokenizer lineTokenizer

A line tokenizer

skipback to summary
private long skip

Number of lines to be skipped.

SKIP_KEYback to summary
private static final String SKIP_KEY

Parameter name for the number of lines to be skipped.

Constructor Detail

TailFilterback to summary
public TailFilter()

Constructor for "dummy" instances.

See Also
BaseFilterReader#BaseFilterReader()
TailFilterback to summary
public TailFilter(final Reader in)

Creates a new filtered reader.

Parameters
in:Reader

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

Method Detail

chainback to summary
public Reader chain(final Reader rdr)

Implements org.apache.tools.ant.filters.ChainableReader.chain.

Creates a new TailFilter using the passed in Reader for instantiation.

Parameters
rdr:Reader

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

Returns:Reader

a new filter based on this configuration, but filtering the specified reader

getLinesback to summary
private long getLines()

Returns the number of lines to be returned in the filtered stream.

Returns:long

the number of lines to be returned in the filtered stream

getSkipback to summary
private long getSkip()

Returns the number of lines to be skipped in the filtered stream.

Returns:long

the number of lines to be skipped in the filtered stream

initializeback to summary
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.

readback to summary
public int read() throws IOException

Overrides java.io.FilterReader.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.

Returns:int

the next character in the resulting stream, or -1 if the end of the resulting stream has been reached

Exceptions
IOException:
if the underlying stream throws an IOException during reading
setLinesback to summary
public void setLines(final long lines)

Sets the number of lines to be returned in the filtered stream.

Parameters
lines:long

the number of lines to be returned in the filtered stream

setSkipback to summary
public void setSkip(final long skip)

Sets the number of lines to be skipped in the filtered stream.

Parameters
skip:long

the number of lines to be skipped in the filtered stream

tailFilterback to summary
private String tailFilter(String line)

implement a tail filter on a stream of lines. line = null is the end of the stream.

Returns:String

"" while reading in the lines, line while outputting the lines null at the end of outputting the lines