Package org.biojava.utils.io
Class RandomAccessReader
- java.lang.Object
-
- java.io.Reader
-
- org.biojava.utils.io.RandomAccessReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public class RandomAccessReader extends java.io.ReaderRandomAccessReaderextendsReaderto provide a means to create bufferedReaders fromRandomAccessFiles.- Since:
- 1.2
- Author:
- Keith James
-
-
Constructor Summary
Constructors Constructor Description RandomAccessReader(java.io.RandomAccessFile raf)Creates a newRandomAccessReaderwrapping theRandomAccessFileand using a default-sized buffer (8192 bytes).RandomAccessReader(java.io.RandomAccessFile raf, int sz)Creates a newRandomAccessReaderwrapping theRandomAccessFileand using a buffer of the specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()closecloses the underlyingRandomAccessFile.longgetFilePointer()getFilePointerreturns the effective position of the pointer in the underlyingRandomAccessFile.longlength()lengthreturns the length of the underlyingRandomAccessFile.intread()readreads one byte from the underlyingRandomAccessFile.intread(char[] cbuf, int off, int len)readreads from the underlyingRandomAccessFileinto an array.voidseek(long pos)seekmoves the pointer to the specified position.
-
-
-
Constructor Detail
-
RandomAccessReader
public RandomAccessReader(java.io.RandomAccessFile raf) throws java.io.IOExceptionCreates a newRandomAccessReaderwrapping theRandomAccessFileand using a default-sized buffer (8192 bytes).- Parameters:
raf- aRandomAccessFileto wrap.- Throws:
java.io.IOException- if an error occurs.
-
RandomAccessReader
public RandomAccessReader(java.io.RandomAccessFile raf, int sz) throws java.io.IOExceptionCreates a newRandomAccessReaderwrapping theRandomAccessFileand using a buffer of the specified size.- Parameters:
raf- aRandomAccessFileto wrap.sz- anintbuffer size.- Throws:
java.io.IOException
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionclosecloses the underlyingRandomAccessFile.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Reader- Throws:
java.io.IOException- if an error occurs.
-
length
public long length() throws java.io.IOExceptionlengthreturns the length of the underlyingRandomAccessFile.- Returns:
- a
long. - Throws:
java.io.IOException- if an error occurs.
-
read
public final int read() throws java.io.IOExceptionreadreads one byte from the underlyingRandomAccessFile.- Overrides:
readin classjava.io.Reader- Returns:
- an
int, -1 if the end of the stream has been reached. - Throws:
java.io.IOException- if an error occurs.
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOExceptionreadreads from the underlyingRandomAccessFileinto an array.- Specified by:
readin classjava.io.Reader- Parameters:
cbuf- achar []array to read into.off- anintoffset in the array at which to start storing chars.len- anintmaximum number of char to read.- Returns:
- an
intnumber of chars read, or -1 if the end of the stream has been reached. - Throws:
java.io.IOException- if an error occurs.
-
getFilePointer
public long getFilePointer() throws java.io.IOExceptiongetFilePointerreturns the effective position of the pointer in the underlyingRandomAccessFile.- Returns:
- a
longoffset. - Throws:
java.io.IOException- if an error occurs.
-
seek
public void seek(long pos) throws java.io.IOExceptionseekmoves the pointer to the specified position.- Parameters:
pos- alongoffset.- Throws:
java.io.IOException- if an error occurs.
-
-