|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.Reader
de.unibi.techfak.jpredictor.sequences.ResetableReader
public class ResetableReader
This class is designed for only one purpose: to make sure, mark and
reset function on a stream. To fulfill this task, you cannot construct
this class other than give a filename, which is used to reopen the
file if necessary. All attempts to reset and mark are redirected to
the underlying BufferedReader and only if it fails, the
class' own handling takes over.
| Field Summary | |
|---|---|
protected long |
countReadBytes
The number of actual read bytes from the underlying reader, set by read(char[], int, int), skip(int) and
read(). |
private java.lang.String |
filename
The name of the file this reader is working with. |
protected long |
mark
The mark on the underlying Reader, set by mark(int) and
used by reset() to read ahead to this position. |
private java.io.Reader |
reader
The file reader all reads are done through. |
| Fields inherited from class java.io.Reader |
|---|
lock |
| Constructor Summary | |
|---|---|
ResetableReader(java.lang.String filename)
Constructs a new ResetableReader object by opening the file with new BufferedReader(new FileReader( filename )) |
|
| Method Summary | |
|---|---|
void |
close()
Closes this Reader. |
void |
mark(int readAheadLimit)
Sets a mark on this stream. |
boolean |
markSupported()
This class supports mark and reset on the stream by reopening the underlying BufferedReader if necessary. |
int |
read()
Reads a character from the file through the underlying BufferedReader. |
int |
read(char[] buffer,
int offset,
int length)
Reads characters from the file through the underlying BufferedReader and writes them into the buffer. |
boolean |
ready()
Tells whether this stream is ready to be read. |
void |
reset()
Resets this reader. |
long |
skip(long n)
Skip characters. |
| Methods inherited from class java.io.Reader |
|---|
read, read |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.lang.String filename
private java.io.Reader reader
protected long countReadBytes
read(char[], int, int), skip(int) and
read().
protected long mark
mark(int) and
used by reset() to read ahead to this position.
| Constructor Detail |
|---|
public ResetableReader(java.lang.String filename)
throws java.io.FileNotFoundException,
java.lang.NullPointerException
new BufferedReader(new FileReader( filename ))
filename - The filename of the file to open.
java.io.FileNotFoundException - If the file does not exists.
java.lang.NullPointerException - If filename is
null.| Method Detail |
|---|
public int read()
throws java.io.IOException
BufferedReader.
read in class java.io.Readerjava.io.IOException - From the underlying BufferedReader.BufferedReader.read()
public int read(char[] buffer,
int offset,
int length)
throws java.io.IOException
BufferedReader and writes them into the buffer.
read in class java.io.Readerbuffer - The buffer to write to.offset - The start of the buffer.length - Number of characters to read maximal.
java.io.IOException - From the underlying BufferedReader.
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.Readerjava.io.IOException - From the underlying BufferedReader.public boolean markSupported()
BufferedReader if necessary.
markSupported in class java.io.Readertrue.
public void mark(int readAheadLimit)
throws java.io.IOException
reset()
it is garantied, that the next readable character is the one a read
would return now. BufferedReader
, but if it is less than 64k, 64k is taken.
mark in class java.io.ReaderreadAheadLimit - The number of characters to read until the mark
on the stream expires.
java.io.IOException - Never.
public void reset()
throws java.io.IOException
Resets this reader. The attempt to reset this reader is redirected
to the underlying BufferedReader. But, since
BufferedReader will always reset to the same mark and is unable
to reset to the beginning of the file, the redirection policy holds
only in case the mark on the reader is not zero. Thus, if the reset
redirection fails or if the mark is zero the file is reopened and, if
neccessary, read to the mark.
Afterwards, the mark on this Reader is set back to zero
(BufferedReader would not do so and this is exactly
the reason why it will always reset to the same mark once set). An
attempt to reset this reader without a previously mark will reset it
to the beginning, which means that the file is reopened. With all
this in mind it is clear, that two subsequent calls to reset()
will always set the reader to the beginning.
reset in class java.io.Readerjava.io.IOException - If the file could not be reopened, or if the
reopened stream could not be read to the mark.
public long skip(long n)
throws java.io.IOException
BufferReader.
skip in class java.io.Readern - The number of characters to skip
java.lang.IllegalArgumentException - If n is negative.
java.io.IOException - If an I/O error occurs.
public boolean ready()
throws java.io.IOException
BufferedReader
ready in class java.io.Readertrue if the next read() is guaranteed not to
block for input, false otherwise. Note that returning
false does not guarantee that the next read will block.
java.io.IOException - If an I/O error occurs
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||