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

public final Class HeadFilter

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

Reads the first n lines of a stream. (Default is first 10 lines.)

Example:

<headfilter lines="3"/>
Or:
<filterreader classname="org.apache.tools.ant.filters.HeadFilter">
   <param name="lines" value="3"/>
</filterreader>

Field Summary

Modifier and TypeField and Description
private static final int
DEFAULT_NUM_LINES

Default number of lines to show

private boolean
eof

Whether this filter is finished

private String
line

the current line from the input stream

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 long
linesRead

Number of lines currently read in.

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
HeadFilter()

Constructor for "dummy" instances.

public
HeadFilter(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 HeadFilter 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 String
headFilter(String line)

implements a head filter on the input 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.

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

Field Detail

DEFAULT_NUM_LINESback to summary
private static final int DEFAULT_NUM_LINES

Default number of lines to show

eofback to summary
private boolean eof

Whether this filter is finished

lineback to summary
private String line

the current line from the input stream

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.

linesReadback to summary
private long linesRead

Number of lines currently read in.

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

HeadFilterback to summary
public HeadFilter()

Constructor for "dummy" instances.

See Also
BaseFilterReader#BaseFilterReader()
HeadFilterback to summary
public HeadFilter(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 HeadFilter 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

headFilterback to summary
private String headFilter(String line)

implements a head filter on the input 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 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.

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