|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.Reader
edu.rice.cs.plt.io.DirectReader
public abstract class DirectReader
A Reader that supports reading directly into a Writer. This class
provides default implementations defined in terms of Reader and Writer
methods. Subclasses can override (at least) readAll(Writer, char[]) and
read(Writer, int, char[]) to provide better implementations (by, for example,
not invoking Reader.read(char[])).
DirectInputStream,
DirectWriter,
DirectOutputStream| Field Summary | |
|---|---|
protected static int |
DEFAULT_BUFFER_SIZE
|
| Fields inherited from class java.io.Reader |
|---|
lock |
| Constructor Summary | |
|---|---|
DirectReader()
|
|
| Method Summary | |
|---|---|
int |
read(Writer w,
int chars)
Read some number of characters from this reader, sending them to the provided Writer. |
int |
read(Writer w,
int chars,
char[] buffer)
Read some number of characters from this reader, sending them to the provided Writer. |
int |
read(Writer w,
int chars,
int bufferSize)
Read some number of characters from this reader, sending them to the provided Writer. |
int |
readAll(Writer w)
Read the full contents of this reader, sending the characters to the provided Writer. |
int |
readAll(Writer w,
char[] buffer)
Read the full contents of this reader, sending the characters to the provided Writer. |
int |
readAll(Writer w,
int bufferSize)
Read the full contents of this reader, sending the characters to the provided Writer. |
| Methods inherited from class java.io.Reader |
|---|
close, mark, markSupported, read, read, read, read, ready, reset, skip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final int DEFAULT_BUFFER_SIZE
| Constructor Detail |
|---|
public DirectReader()
| Method Detail |
|---|
public int read(Writer w,
int chars)
throws IOException
Writer.
The default implementation invokes read(Writer, int, int) with the minimum of
chars and DEFAULT_BUFFER_SIZE. Subclasses that know the size of this reader's
remaining contents, or that do not rely on a buffer in read(Writer, int, char[]),
should override this method.
w - A writer to be written tochars - The number of characters to read
-1 if this reader is at the end of file; otherwise, the number of characters read
IOException - If an error occurs during reading or writing
public int read(Writer w,
int chars,
int bufferSize)
throws IOException
Writer.
The default implementation invokes read(Writer, int, char[]) with a newly-allocated array
of the given size. Subclasses that do not rely on a buffer in read(Writer, int, char[])
should override this method.
w - A writer to be written tochars - The number of characters to readbufferSize - The size of buffer to use (if necessary). Smaller values may reduce the amount of
memory required; larger values may increase performance of large readers
-1 if this reader is at the end of file; otherwise, the number of characters read
IOException - If an error occurs during reading or writing
IllegalArgumentException - If bufferSize <= 0
public int read(Writer w,
int chars,
char[] buffer)
throws IOException
Writer.
The given buffer is useful in repeated read invocations to avoid unnecessary
memory allocation. The default implementation repeatedly fills the given buffer via a
Reader.read(char[], int, int) operation, then writes it via
Writer.write(char[], int, int). Subclasses that do not require an external buffer
should override this method.
w - A writer to be written tochars - The number of characters to readbuffer - A buffer used to copy characters from this reader to the writer. Note that this is only
used to avoid unnecessary memory allocation. No assumptions are made about the buffer's
contents (which may be overwritten), and no assumptions should be made about the contents
of the buffer after the method invocation.
-1 if this reader is at the end of file; otherwise, the number of characters read
IOException - If an error occurs during reading or writing
IllegalArgumentException - If buffer has size 0
public int readAll(Writer w)
throws IOException
Writer.
The method will block until an end-of-file is reached. The default implementation invokes
readAll(Writer, int) with DEFAULT_BUFFER_SIZE. Subclasses that know the
size of this reader's remaining contents, or that do not rely on a buffer in
readAll(Writer, char[]), should override this method.
w - A writer to be written to
-1 if this reader is at the end of file; otherwise, the number of characters read
(or, if the number is too large, Integer.MAX_VALUE)
IOException - If an error occurs during reading or writing
public int readAll(Writer w,
int bufferSize)
throws IOException
Writer.
The method will block until an end-of-file is reached. The default implementation invokes
readAll(Writer, char[]) with a newly-allocated array of the given size. Subclasses
that do not rely on a buffer in readAll(Writer, char[]) should override this method.
w - A writer to be written tobufferSize - The size of buffer to use (if necessary). Smaller values may reduce the amount of
memory required; larger values may increase performance of large readers
-1 if this reader is at the end of file; otherwise, the number of characters read
(or, if the number is too large, Integer.MAX_VALUE)
IOException - If an error occurs during reading or writing
IllegalArgumentException - If bufferSize <= 0
public int readAll(Writer w,
char[] buffer)
throws IOException
Writer.
The given buffer is useful in repeated readAll invocations to avoid unnecessary
memory allocation. The method will block until an end-of-file is reached. The default
implementation repeatedly fills the given buffer via a Reader.read(char[]) operation,
then writes it via Writer.write(char[]). Subclasses that do not require an external buffer
should override this method.
w - A writer to be written tobuffer - A buffer used to copy characters from this reader to the writer. Note that this is only
used to avoid unnecessary memory allocation. No assumptions are made about the buffer's
contents (which may be overwritten), and no assumptions should be made about the contents
of the buffer after the method invocation.
-1 if this reader is at the end of file; otherwise, the number of characters read
(or, if the number is too large, Integer.MAX_VALUE)
IOException - If an error occurs during reading or writing
IllegalArgumentException - If buffer has size 0
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||