HeadFilter (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.filters, class: HeadFilter

# Class HeadFilter

java.lang.Object
java.io.Reader
java.io.FilterReader
org.apache.tools.ant.filters.BaseFilterReader
org.apache.tools.ant.filters.BaseParamFilterReader
org.apache.tools.ant.filters.HeadFilter

All Implemented Interfaces:
  `Closeable, AutoCloseable, Readable, ChainableReader, Parameterizable`

public final class HeadFilter extends BaseParamFilterReader implements ChainableReader
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

  ### Fields inherited from class FilterReader

  `in`

  ### Fields inherited from class Reader

  `lock`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HeadFilter()`
  Constructor for "dummy" instances.
  `HeadFilter(Reader in)`
  Creates a new filtered reader.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Reader`
  `chain(Reader rdr)`
  Creates a new HeadFilter using the passed in Reader for instantiation.
  `int`
  `read()`
  Returns the next character in the filtered stream.
  `void`
  `setLines(long lines)`
  Sets the number of lines to be returned in the filtered stream.
  `void`
  `setSkip(long skip)`
  Sets the number of lines to be skipped in the filtered stream.

  ### Methods inherited from class BaseParamFilterReader

  `getParameters, setParameters`
  Modifier and Type
  Method
  Description
  `protected final Parameter[]`
  `getParameters()`
  Returns the parameters to be used by this filter.
  `final void`
  `setParameters(Parameter... parameters)`
  Sets the parameters used by this filter, and sets the filter to an uninitialized status.

  ### Methods inherited from class BaseFilterReader

  `getInitialized, getProject, read, readFully, readLine, setInitialized, setProject, skip`
  Modifier and Type
  Method
  Description
  `protected final boolean`
  `getInitialized()`
  Returns the initialized status.
  `protected final Project`
  `getProject()`
  Returns the project this filter is part of.
  `final int`
  `read(char[] cbuf, int off, int len)`
  Reads characters into a portion of an array.
  `protected final String`
  `readFully()`
  Reads to the end of the stream, returning the contents as a String.
  `protected final String`
  `readLine()`
  Reads a line of text ending with '\n' (or until the end of the stream).
  `protected final void`
  `setInitialized(boolean initialized)`
  Sets the initialized status.
  `final void`
  `setProject(Project project)`
  Sets the project to work with.
  `final long`
  `skip(long n)`
  Skips characters.

  ### Methods inherited from class FilterReader

  `close, mark, markSupported, ready, reset`

  ### Methods inherited from class Reader

  `nullReader, of, read, read, readAllAsString, readAllLines, transferTo`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### HeadFilter

    public HeadFilter()
    Constructor for "dummy" instances.
    See Also:
      - `BaseFilterReader()`

  - ### HeadFilter

    public HeadFilter(Reader in)
    Creates a new filtered reader.
    Parameters:
      `in` - A Reader object providing the underlying stream. Must not be `null`.

- ## Method Details

  - ### read

    public int read() throws IOException
    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.
    Overrides:
      `read` in class `FilterReader`
    Returns:
      the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
    Throws:
      `IOException` - if the underlying stream throws an IOException during reading

  - ### setLines

    public void setLines(long lines)
    Sets the number of lines to be returned in the filtered stream.
    Parameters:
      `lines` - the number of lines to be returned in the filtered stream

  - ### setSkip

    public void setSkip(long skip)
    Sets the number of lines to be skipped in the filtered stream.
    Parameters:
      `skip` - the number of lines to be skipped in the filtered stream

  - ### chain

    public Reader chain(Reader rdr)
    Creates a new HeadFilter using the passed in Reader for instantiation.
    Specified by:
      `chain` in interface `ChainableReader`
    Parameters:
      `rdr` - A Reader object providing the underlying stream. Must not be `null`.
    Returns:
      a new filter based on this configuration, but filtering the specified reader