|
|||||||||
| 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.MultiFileReader
public class MultiFileReader
A MultiFileReader represents the logical concatenation of
other Readers. It starts out with an ordered collection
of streams and reads from the first one until end of file is reached,
whereupon the delimiter string is included and then it reads from the
second one, and so on, until end of file is reached on the last of the
contained Readers. Thus, it works similar to the
SequenceInputStream class.
The purpose of this class is to make sure mark() and
reset() function properly. Thus it is recommended to add
readers by giving the filenames. The class then creates
ResetableReader from the filenames and redirects attempts
to mark and reset to the stream.
While reseting it may be that a file must be reopened. Thus thrown
IOExceptions may be FileNotFoundException
instead.
| Field Summary | |
|---|---|
private java.io.Reader |
actReader
The reader actually used for read and write operations. |
private int |
actualReader
The actual position in the readers vector. |
private java.util.Vector |
filenames
The storage container of the readers filenames. |
private int |
markedReader
The reader marked. |
private boolean |
markSupported
Changed when adding Readers through one of the
add-methods. |
private java.lang.String |
readerDelimiter
The string used as a delimiter between the different reader in readers. |
private java.util.Vector |
readers
The storage container of the subsequent readers. |
| Fields inherited from class java.io.Reader |
|---|
lock |
| Constructor Summary | |
|---|---|
MultiFileReader(java.lang.String delimiter)
Constructs a new MultiFileReader object with the given reader delimiter. |
|
| Method Summary | |
|---|---|
void |
add(java.io.Reader reader)
Adds a Reader to the underlying storage container. |
void |
add(java.lang.String filename)
Adds a new ResetableReader to the vector of
subsequence readers. |
void |
close()
Closes and disbands all Readers stored in this class. |
static java.lang.String |
filesToString(java.io.File[] files)
Joins the filenames of all given Files into one string. |
java.io.Reader |
get(int index)
Returns a reader for a given index. |
java.lang.String |
getFilename(int index)
Returns the filename for a given index. |
static java.io.Reader |
getReader(java.lang.String names)
Creates either a MultiFileReader or a
ResetableReader from the filenames comprised in
names. |
void |
mark(int readAheadLimit)
Sets a mark on this stream. |
boolean |
markSupported()
This class supports mark and reset only if all reader in this class support it, too. |
int |
read(char[] buffer,
int offset,
int length)
Reads characters from one of the underlying readers. |
boolean |
ready()
Tells whether this stream is ready to be read. |
void |
reset()
Sets back the list of readers to the most recent mark. |
int |
size()
Returns the amount of readers combined in this MultiFileReader
. |
long |
skip(long n)
Skip characters. |
static java.lang.String |
testFilenames(java.lang.String names)
Tests the filenames to be existing files. |
java.lang.String |
toString()
Prints the quoted filenames seperated by comma. |
| Methods inherited from class java.io.Reader |
|---|
read, read, read |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private java.util.Vector readers
private java.util.Vector filenames
null
name in here stands for either the delimiter string or a reader
added through the add( Reader ) method.
add(Reader)private int actualReader
readers vector.
private int markedReader
readers vector. A value
of -1 means that no mark is set yet.
private java.io.Reader actReader
private java.lang.String readerDelimiter
readers.
private boolean markSupported
Readers through one of the
add-methods. Stays true if all added
reader support mark and reset methods.
| Constructor Detail |
|---|
public MultiFileReader(java.lang.String delimiter)
delimiter - The delimiter read between the different reader.
May be null.| Method Detail |
|---|
public void add(java.lang.String filename)
throws java.io.FileNotFoundException,
java.lang.NullPointerException
ResetableReader to the vector of
subsequence readers.
filename - The filename of the file to open.
java.io.FileNotFoundException - If the file could not be found.
java.lang.NullPointerException - If filename is null.
public void add(java.io.Reader reader)
throws java.lang.NullPointerException
Reader to the underlying storage container.
Make sure the reader supports the mark() and
reset() operations properly. And further make sure, that
the reader works like a ResetableReader the way,
that two subsequent resets set back the reader to the beginning
and not to the mark.
reader - The reader to add.
java.lang.NullPointerException - If reader is null.public void close()
Readers stored in this class.
Does not throw any exceptions. After calling this method you must
not try to add new readers to this class or call any other method.
close in interface java.io.Closeableclose in class java.io.Readerpublic int size()
MultiFileReader
. If no delimiter was given, the size is the number of readers
added previously, otherwise the size is (2 x #addedReader - 1).
public java.io.Reader get(int index)
throws java.lang.IndexOutOfBoundsException
index - Points at the reader to return.
java.lang.IndexOutOfBoundsException - If index is less than zero or greater
or equal to size().size()
public java.lang.String getFilename(int index)
throws java.lang.IndexOutOfBoundsException
null is
returned the corresponding reader is either the delimiter or was
added through the add( Reader ) method without providing
a filename. If the delimiter string was set when this class was
constructed, every second index null is returned.
index - Index of the reader whoms filename is to return.
null in some
cases.
java.lang.IndexOutOfBoundsException - If index is less than zero or greater
or equal to size().size()
public int read(char[] buffer,
int offset,
int length)
throws java.io.IOException
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 Reader, e.g. if
the file could not be found anymore.public boolean markSupported()
mark() to that reader. After a
reset all Reader after the marked one are re-set and the
marked one got the reset attempt.
If only one underlying reader does not support mark and reset, it
is skipped for the whole class.
markSupported in class java.io.Readertrue iff all underlying readers return true by
this method, false otherwise.
public void mark(int readAheadLimit)
throws java.io.IOException
reset()
it is garantied, that the next readable character is the one a read
would now return.
The parameter is forwarded without change to the underlying
Reader.
- Overrides:
mark in class java.io.Reader
- Parameters:
readAheadLimit - The number of characters to read until the mark
on the stream expires.
- Throws:
java.io.IOException - If the actual reader does not support mark and
reset.- See Also:
ResetableReader.mark(int)
public void reset()
throws java.io.IOException
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.ResetableReader.reset()
public long skip(long n)
throws java.io.IOException
read(char[], int, int)-method.
skip in class java.io.Readern - The number of characters to skip
java.io.IOException - If an I/O error occurs.
public boolean ready()
throws java.io.IOException
Reader
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 occurspublic java.lang.String toString()
toString in class java.lang.Objectpublic static java.lang.String testFilenames(java.lang.String names)
names might contain one or more quoted filenames,
seperated by comma (e.g. '"/homes/a", "/digit", "/homes/a+b"').
From every filename a File-object is created
and, if isFile() returned true it
is included in the returned list, otherwise discarded.
names - An collection of filenames.
add(String),
toString(),
File.isFile()public static java.lang.String filesToString(java.io.File[] files)
Files into one string.
The convention is, that each filename is double-quoted, and two
filenames are seperated with ", " (comma space). If a file is
null, it is ignored. if files is
null the empty String is returned.
files - A number of Files whos names are to be
concatenated.
String of concatenated, comma-delimited,
double-quoted filenames.
public static java.io.Reader getReader(java.lang.String names)
throws java.io.FileNotFoundException,
java.lang.NullPointerException
MultiFileReader or a
ResetableReader from the filenames comprised in
names. If only one filename is given one
ResetableReader is returned. Multiple filenames
in names must be double-quoted and delimited by
", " (comma space).
names - The filenames to be concatenated.
MultiFileReader or a
ResetableReader.
java.io.FileNotFoundException - If a file was not found.
java.lang.NullPointerException - If a names is
null.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||