|
|||||||||
| 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.SequenceReader
public abstract class SequenceReader
This class is designed as a wrapper for other readers with two purposes.
First, it provides methods for filtered reads on a Reader,
readFiltered() and readUnfiltered().
All implemented methods use these two methods, and even read()
is redirected to call readFiltered().
Note, that you should read the Reader only through the provided methods.
The methods markSupported(), mark(int) and
reset() are forwarded to the underlying Reader.
The second purpose is sequence observation. While reading the input reader
derived filters like FastaFilter write a predefined
structure (SequenceInformationBlock) to get all sequence
fragments from the Reader. For instance, sequence fragments in FASTA files
are separated by a line starting with '>'.
When the filtered reading method arrives at a sequence block delimiter
a NewSequenceBlockException is thrown. This exception is
derived from IOException and has as message string "NSBE".
The initial sequence block is always directly created while constructing
this class. Thus it is garantied, that even if no block delimiter is found
the filtered characters are counted properly.
By this it is also possible to use a FastaReader on a file,
where the '>' is missing, but where a sequence is present. The name and
description of the sequence are then unknown.
By calling the method sequences() you will get a
SequenceEnumeration of all sequences present in the file.
Note, that the results are undefined, if you use more than one
Sequence returned by the method nextSequence()
concurrently.
SequenceInformationBlock| Field Summary | |
|---|---|
protected long |
countCharsRead
Counts the number of chars read. |
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. |
protected java.util.Vector |
sequenceBlocks
Holds the SequenceInformationBlocks. |
| Fields inherited from class java.io.Reader |
|---|
lock |
| Constructor Summary | |
|---|---|
SequenceReader(java.io.Reader reader)
Constructor. |
|
| Method Summary | |
|---|---|
void |
close()
Closes this Reader. |
void |
mark(int readAheadLimit)
Sets a mark on the stream. |
boolean |
markSupported()
The result from the underlying readers method is returned. |
int |
read()
Reads a character from the stream through the method readFiltered(). |
int |
read(char[] buffer,
int offset,
int length)
Reads valid characters from the file through calls to readFiltered() and writes them into the buffer. |
protected abstract int |
readFiltered()
Reads characters from the stream until the next valid character occurs which is returned. |
protected java.lang.String |
readLine(int len)
Reads up to len characters from the line and stores them
in a new string. |
protected int |
readUnfiltered()
Reads a character from the stream and returns it unfiltered, just like a call to this.reader.read(). |
void |
reset()
The underlying Reader is re-set and all
SequenceInformationBlocks lying beyond the
mark are deleted. |
SequenceEnumeration |
sequences()
Returns a SequenceEnumeration-object usable for going
through all sequences in this Reader sequentially. |
long |
skip(long n)
Skip characters. |
| Methods inherited from class java.io.Reader |
|---|
read, read, ready |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.Vector sequenceBlocks
SequenceInformationBlocks.
protected long countCharsRead
readFiltered().
private java.io.Reader reader
protected long mark
mark(int) and
used by reset() to read ahead to this position.
| Constructor Detail |
|---|
public SequenceReader(java.io.Reader reader)
throws java.lang.NullPointerException
Reader and inits the
first SequenceInformationBlock. Resets the given
Reader because maybe it was already read.
reader - The Reader to read from.
java.lang.NullPointerException - If the given Reader
is nullSequenceInformationBlock| Method Detail |
|---|
public int read()
throws NewSequenceBlockException
readFiltered().
read in class java.io.ReaderNewSequenceBlockException - An IOException
thrown when a new sequence occurs within the file.
protected abstract int readFiltered()
throws NewSequenceBlockException
NewSequenceBlockException - An IOException
thrown when a new sequence occurs within the file.protected int readUnfiltered()
this.reader.read().
Any IOException is caught and -1 is returned as well.
public int read(char[] buffer,
int offset,
int length)
readFiltered() and writes them into the buffer.
This method does read characters only within a sequence block
and not till the end of file.
read in class java.io.Readerbuffer - The char buffer to write the data into.offset - Start index in the buffer.length - Maximal number of chars to write.
readFiltered()protected java.lang.String readLine(int len)
Reads up to len characters from the line and stores them
in a new string. The string is returned even if the line still
contains characters to read. The returned string always contains
the newline character '\n' if it was read.
readUnfiltered().
Set len=0 to read the whole line into the string and set
len=-1 to discard every character of the line and return
the empty string in case a EOF was observed or "\n" in case a
end-of-line was reached.
Reader.readUnfiltered()
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.Readerjava.io.IOExceptionpublic SequenceEnumeration sequences()
SequenceEnumeration-object usable for going
through all sequences in this Reader sequentially.
SequenceEnumeration-object.public boolean markSupported()
markSupported in class java.io.Readertrue, if mark and reset are supported,
false otherwise.
public void mark(int readAheadLimit)
throws java.io.IOException
reset()
the next readable character is the one a read would now return.
- Overrides:
mark in class java.io.Reader
- Parameters:
readAheadLimit -
- Throws:
java.io.IOException - If the underlying stream does not support mark(),
or if some other I/O error occurs
public void reset()
throws java.io.IOException
Reader is re-set and all
SequenceInformationBlocks lying beyond the
mark are deleted.
reset in class java.io.Readerjava.io.IOException - If the reset operation is not supported
public long skip(long n)
throws NewSequenceBlockException,
java.io.IOException
readFiltered.
skip in class java.io.Readern - The number of characters to skip
java.io.IOException - If an I/O error occurs.
NewSequenceBlockException - If a new sequence is reached.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||