Package java.io
Class FilterReader
- java.lang.Object
-
- java.io.Reader
-
- java.io.FilterReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
- Direct Known Subclasses:
PushbackReader
public abstract class FilterReader extends Reader
Wraps an existingReaderand performs some transformation on the input data while it is being read. Transformations can be anything from a simple byte-wise filtering input data to an on-the-fly compression or decompression of the underlying reader. Readers that wrap another reader and provide some additional functionality on top of it usually inherit from this class.- See Also:
FilterWriter
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFilterReader(Reader in)Constructs a new FilterReader on the Readerin.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this reader.voidmark(int readlimit)Sets a mark position in this reader.booleanmarkSupported()Indicates whether this reader supportsmark()andreset().intread()Reads a single character from the filtered reader and returns it as an integer with the two higher-order bytes set to 0.intread(char[] buffer, int offset, int count)Reads up tocountcharacters from the filtered reader and stores them in the byte arraybufferstarting atoffset.booleanready()Indicates whether this reader is ready to be read without blocking.voidreset()Resets this reader's position to the last marked location.longskip(long charCount)SkipscharCountcharacters in this reader.
-
-
-
Field Detail
-
in
protected Reader in
The target Reader which is being filtered.
-
-
Constructor Detail
-
FilterReader
protected FilterReader(Reader in)
Constructs a new FilterReader on the Readerin.- Parameters:
in- The non-null Reader to filter reads on.
-
-
Method Detail
-
close
public void close() throws IOExceptionCloses this reader. This implementation closes the filtered reader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException- if an error occurs while closing this reader.
-
mark
public void mark(int readlimit) throws IOExceptionSets a mark position in this reader. The parameterreadlimitindicates how many bytes can be read before the mark is invalidated. Sendingreset()will reposition this reader back to the marked position, provided thatreadlimithas not been surpassed.This implementation sets a mark in the filtered reader.
- Overrides:
markin classReader- Parameters:
readlimit- the number of bytes that can be read from this reader before the mark is invalidated.- Throws:
IOException- if an error occurs while marking this reader.- See Also:
markSupported(),reset()
-
markSupported
public boolean markSupported()
Indicates whether this reader supportsmark()andreset(). This implementation returns whether the filtered reader supports marking.- Overrides:
markSupportedin classReader- Returns:
trueifmark()andreset()are supported by the filtered reader,falseotherwise.- See Also:
mark(int),reset(),skip(long)
-
read
public int read() throws IOExceptionReads a single character from the filtered reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the filtered reader has been reached.- Overrides:
readin classReader- Returns:
- The character read or -1 if the end of the filtered reader has been reached.
- Throws:
IOException- if an error occurs while reading from this reader.
-
read
public int read(char[] buffer, int offset, int count) throws IOExceptionReads up tocountcharacters from the filtered reader and stores them in the byte arraybufferstarting atoffset. Returns the number of characters actually read or -1 if no characters were read and the end of the filtered reader was encountered.- Specified by:
readin classReader- Throws:
IOException- if an error occurs while reading from this reader.
-
ready
public boolean ready() throws IOExceptionIndicates whether this reader is ready to be read without blocking. If the result istrue, the nextread()will not block. If the result isfalse, this reader may or may not block whenread()is sent.- Overrides:
readyin classReader- Returns:
trueif this reader will not block whenread()is called,falseif unknown or blocking will occur.- Throws:
IOException- if the reader is closed or some other I/O error occurs.- See Also:
Reader.read(),Reader.read(char[]),Reader.read(char[], int, int)
-
reset
public void reset() throws IOExceptionResets this reader's position to the last marked location. Invocations ofread()andskip()will occur from this new location. If this reader was not marked, the behavior depends on the implementation ofreset()in the Reader subclass that is filtered by this reader. The default behavior for Reader is to throw anIOException.- Overrides:
resetin classReader- Throws:
IOException- if a problem occurred or the filtered reader does not supportmark()andreset().- See Also:
mark(int),markSupported()
-
skip
public long skip(long charCount) throws IOExceptionSkipscharCountcharacters in this reader. Subsequent calls toreadwill not return these characters unlessresetis used. The default implementation is to skip characters in the filtered reader.- Overrides:
skipin classReader- Returns:
- the number of characters actually skipped.
- Throws:
IOException- if the filtered reader is closed or some other I/O error occurs.- See Also:
mark(int),markSupported(),reset()
-
-