DthingApi
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
java.io.Reader Class Referenceabstract
Inheritance diagram for java.io.Reader:
com.yarlungsoft.charset.StreamReader java.io.BufferedReader java.io.InputStreamReader com.yarlungsoft.charset.ISO8859_1_Reader com.yarlungsoft.charset.UTF_8_Reader

Public Member Functions

abstract void close () throws IOException
 
void mark (int readLimit) throws IOException
 
boolean markSupported ()
 
int read () throws IOException
 
int read (char[] buf) throws IOException
 
abstract int read (char[] buf, int offset, int count) throws IOException
 
boolean ready () throws IOException
 
void reset () throws IOException
 
long skip (long charCount) throws IOException
 

Protected Member Functions

 Reader ()
 
 Reader (Object lock)
 

Protected Attributes

Object lock
 

Detailed Description

The base class for all readers. A reader is a means of reading data from a source in a character-wise manner. Some readers also support marking a position in the input and returning to this position later.

This abstract class does not provide a fully working implementation, so it needs to be subclassed, and at least the read(char[], int, int) and close() methods needs to be overridden. Overriding some of the non-abstract methods is also often advised, since it might result in higher efficiency.

Many specialized readers for purposes like reading from a file already exist in this package.

See also
Writer

Constructor & Destructor Documentation

◆ Reader() [1/2]

java.io.Reader.Reader ( )
inlineprotected

Constructs a new

with

this

as the object used to synchronize critical sections.

◆ Reader() [2/2]

java.io.Reader.Reader ( Object  lock)
inlineprotected

Constructs a new

with

used to synchronize critical sections.

Parameters
lockthe
Object
used to synchronize critical sections.
Exceptions
NullPointerExceptionif is
null
.

Member Function Documentation

◆ close()

abstract void java.io.Reader.close ( ) throws IOException
abstract

Closes this reader. Implementations of this method should free any resources associated with the reader.

Exceptions
IOExceptionif an error occurs while closing this reader.

◆ mark()

void java.io.Reader.mark ( int  readLimit) throws IOException
inline

Sets a mark position in this reader. The parameter

readLimit

indicates how many characters can be read before the mark is invalidated. Calling

will reposition the reader back to the marked position if

readLimit

has not been surpassed.

This default implementation simply throws an

IOException

; subclasses must provide their own implementation.

Parameters
readLimitthe number of characters that can be read before the mark is invalidated.
Exceptions
IllegalArgumentExceptionif
readLimit < 0
.
IOExceptionif an error occurs while setting a mark in this reader.
See also
markSupported()
reset()

◆ markSupported()

boolean java.io.Reader.markSupported ( )
inline

Indicates whether this reader supports the

mark()

and

methods. This default implementation returns

false

.

Returns
always
false
.

◆ read() [1/3]

int java.io.Reader.read ( ) throws IOException
inline

Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the end of the reader has been reached.

Returns
the character read or -1 if the end of the reader has been reached.
Exceptions
IOExceptionif this reader is closed or some other I/O error occurs.

◆ read() [2/3]

int java.io.Reader.read ( char []  buf) throws IOException
inline

Reads characters from this reader and stores them in the character array

buf

starting at offset 0. Returns the number of characters actually read or -1 if the end of the reader has been reached.

Parameters
bufcharacter array to store the characters read.
Returns
the number of characters read or -1 if the end of the reader has been reached.
Exceptions
IOExceptionif this reader is closed or some other I/O error occurs.

◆ read() [3/3]

abstract int java.io.Reader.read ( char []  buf,
int  offset,
int  count 
) throws IOException
abstract

Reads at most

count

characters from this reader and stores them at

offset

in the character array

buf

. Returns the number of characters actually read or -1 if the end of the reader has been reached.

Parameters
bufthe character array to store the characters read.
offsetthe initial position in
buffer
to store the characters read from this reader.
countthe maximum number of characters to read.
Returns
the number of characters read or -1 if the end of the reader has been reached.
Exceptions
IOExceptionif this reader is closed or some other I/O error occurs.

◆ ready()

boolean java.io.Reader.ready ( ) throws IOException
inline

Indicates whether this reader is ready to be read without blocking. Returns

true

if this reader will not block when

is called,

false

if unknown or blocking will occur. This default implementation always returns

false

.

Returns
always
false
.
Exceptions
IOExceptionif this reader is closed or some other I/O error occurs.
See also
read()
#read(char[])
#read(char[], int, int)

◆ reset()

void java.io.Reader.reset ( ) throws IOException
inline

Resets this reader's position to the last

mark()

location. Invocations of

read()

and

skip()

will occur from this new location. If this reader has not been marked, the behavior of

is implementation specific. This default implementation throws an

IOException

.

Exceptions
IOExceptionalways thrown in this default implementation.
See also
mark(int)
markSupported()

◆ skip()

long java.io.Reader.skip ( long  charCount) throws IOException
inline

Skips

charCount

characters in this reader. Subsequent calls of

methods will not return these characters unless

is used. This method may perform multiple reads to read

charCount

characters.

Returns
the number of characters actually skipped.
Exceptions
IllegalArgumentExceptionif
charCount < 0
.
IOExceptionif this reader is closed or some other I/O error occurs.
See also
mark(int)
markSupported()
reset()

Member Data Documentation

◆ lock

Object java.io.Reader.lock
protected

The object used to synchronize access to the reader.


The documentation for this class was generated from the following file: