public class ReaderSource extends java.lang.Object implements TokenizerSource
This implementation of the TokenizerSource interface uses the JDK
Reader class to realize the requested functionality. Note that
the backing Reader can be changed during the parse operations of
the Tokenizer instance that accesses this ReaderSource.
de.susebox.java.util.Tokenizer,
de.susebox.java.util.AbstractTokenizer,
Reader| Constructor and Description |
|---|
ReaderSource()
The default constructor constructs a
ReaderSource instance
that reads from nowhere. |
ReaderSource(java.io.File file)
This Constructor takes an
File to create a Reader
from. |
ReaderSource(java.io.InputStream is)
This Constructor takes an
InputStream. |
ReaderSource(java.io.Reader reader)
Constructing an
ReaderSource object with the given Reader
instance to get input data from. |
ReaderSource(java.lang.String path)
This Constructor takes an
String as a file path to create
a Reader from. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
This method can be called to close streams (either
Reader
or InputStream passed to the constructors or implicitely
created when this ReaderSource is setup. |
java.io.Reader |
getReader()
Retrieving the current
Reader. |
int |
read(char[] cbuf,
int offset,
int maxChars)
The method calls the
Reader.read(char[], int, int) method of
the currently backing Reader. |
void |
setReader(java.io.Reader reader)
Setting the backing
Reader instance. |
public ReaderSource()
ReaderSource instance
that reads from nowhere. A call to the read(char[], int, int) method will immediately
return the end-of-file condition.read(char[], int, int)public ReaderSource(java.io.Reader reader)
ReaderSource object with the given Reader
instance to get input data from. null is a valid value. The
read(char[], int, int) method will return an end-of-file condition in that case.
Reader instance can be closed manually or by
calling the close() method of this ReaderSource object.reader - the backing Reader or nullpublic ReaderSource(java.io.InputStream is)
InputStream. It is comfortable
when You dont have a Reader in the first place. However,
when using this constructor, the method close() should be called
after tokenizing has been finished. It will also close the given
InputStream.
null leading to an end-of-file condition
in the first call to read(char[], int, int).is - the input stream or nullpublic ReaderSource(java.io.File file)
throws java.io.IOException
File to create a Reader
from. When using this constructor, the method close() should be
called after tokenizing has been finished.
null leading to an end-of-file condition
in the first call to read(char[], int, int).file - the File object that should be read or nulljava.io.IOExceptionpublic ReaderSource(java.lang.String path)
throws java.io.IOException
String as a file path to create
a Reader from. When using this constructor, the method
close() should be called after tokenizing has been finished.
null leading to an end-of-file condition
in the first call to read(char[], int, int).path - a file path or nulljava.io.IOExceptionpublic int read(char[] cbuf,
int offset,
int maxChars)
throws java.lang.Exception
Reader.read(char[], int, int) method of
the currently backing Reader. If no Reader is set so far,
-1 (end-of-file) is returned.read in interface TokenizerSourcecbuf - buffer to receive dataoffset - position from where the data should be inserted in cbufmaxChars - maximum number of characters to be read into cbufjava.lang.Exception - anything that could happen during read, most likely IOExceptionpublic void close()
Reader
or InputStream passed to the constructors or implicitely
created when this ReaderSource is setup.
Reader.close() and InputStream.close()
probably combined with an exception handling to catch IOException.public void setReader(java.io.Reader reader)
Reader instance. null is a
valid value. The read(char[], int, int) method will return no data (end-of-file) in
that case.reader - the backing Readerread(char[], int, int),
getReader()public java.io.Reader getReader()
Reader. The method may return null
if a setReader(java.io.Reader) with null has occured before.Reader or nullsetReader(java.io.Reader)