java.lang.Object
java.io.Reader
soapical.util.MultiReader
- public class MultiReader
- extends java.io.Reader
A decorator which allows you to reuse a Reader. This copies the
contents of the Reader to an internal buffer. Before you re-use
the reader, you will have to call the reopen function.
- Version:
- $Revision: 1.1 $
$Date: 2003/05/04 21:03:33 $
|
Method Summary |
void |
close()
Closes the stream. |
private void |
copyReader()
|
java.io.Reader |
getCopy()
Return a copy of the Reader. |
boolean |
isClosed()
|
int |
read(char[] cbuf,
int off,
int len)
Read chars from a stream and stores them into a caller
supplied buffer. |
void |
reopen()
Allows this MultiReader to be reused. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_logger
static org.apache.log4j.Logger _logger
_buffer
private java.lang.StringBuffer _buffer
_reader
private java.io.Reader _reader
_isClosed
private boolean _isClosed
_isUntouched
private boolean _isUntouched
COPY_BUFFER_SIZE
static final int COPY_BUFFER_SIZE
- See Also:
- Constant Field Values
MultiReader
public MultiReader(java.io.Reader reader)
isClosed
public boolean isClosed()
reopen
public void reopen()
throws java.io.IOException
- Allows this MultiReader to be reused. You have to call this every
first time after closing the reader.
Forcing people to use this function makes MultiReader less
convenient but more predictable to use. Otherwise, it would
silently loop back to the beginning, and instead of getting
a proper IOException, people would get the
beginning of the stream again.
getCopy
public java.io.Reader getCopy()
throws java.io.IOException
- Return a copy of the Reader. This is if you want to read in
multiple threads.
copyReader
private void copyReader()
throws java.io.IOException
close
public void close()
throws java.io.IOException
- Description copied from class:
java.io.Reader
- Closes the stream. Any futher attempts to read from the
stream may generate an
IOException.
read
public int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
- Description copied from class:
java.io.Reader
- Read chars from a stream and stores them into a caller
supplied buffer. It starts storing the data at index
offset
into the buffer and attempts to read len chars. This method
can return before reading the number of chars requested. The actual
number of chars read is returned as an int. A -1 is returned to indicate
the end of the stream.
This method will block until some data can be read.
This method operates by calling the single char read() method
in a loop until the desired number of chars are read. The read loop
stops short if the end of the stream is encountered or if an IOException
is encountered on any read operation except the first. If the first
attempt to read a chars fails, the IOException is allowed to propagate
upward. And subsequent IOException is caught and treated identically
to an end of stream condition. Subclasses can (and should if possible)
override this method to provide a more efficient implementation.