Package org.biojava.utils.io
Class RandomAccessReader
- java.lang.Object
-
- java.io.Reader
-
- org.biojava.utils.io.RandomAccessReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
public class RandomAccessReader extends Reader
RandomAccessReaderextendsReaderto provide a means to create bufferedReaders fromRandomAccessFiles.- Since:
- 1.2
- Author:
- Keith James
-
-
Constructor Summary
Constructors Constructor Description RandomAccessReader(RandomAccessFile raf)Creates a newRandomAccessReaderwrapping theRandomAccessFileand using a default-sized buffer (8192 bytes).RandomAccessReader(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.-
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, ready, reset, skip, transferTo
-
-
-
-
Constructor Detail
-
RandomAccessReader
public RandomAccessReader(RandomAccessFile raf) throws IOException
Creates a newRandomAccessReaderwrapping theRandomAccessFileand using a default-sized buffer (8192 bytes).- Parameters:
raf- aRandomAccessFileto wrap.- Throws:
IOException- if an error occurs.
-
RandomAccessReader
public RandomAccessReader(RandomAccessFile raf, int sz) throws IOException
Creates a newRandomAccessReaderwrapping theRandomAccessFileand using a buffer of the specified size.- Parameters:
raf- aRandomAccessFileto wrap.sz- anintbuffer size.- Throws:
IOException
-
-
Method Detail
-
close
public void close() throws IOException
closecloses the underlyingRandomAccessFile.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException- if an error occurs.
-
length
public long length() throws IOException
lengthreturns the length of the underlyingRandomAccessFile.- Returns:
- a
long. - Throws:
IOException- if an error occurs.
-
read
public final int read() throws IOException
readreads one byte from the underlyingRandomAccessFile.- Overrides:
readin classReader- Returns:
- an
int, -1 if the end of the stream has been reached. - Throws:
IOException- if an error occurs.
-
read
public int read(char[] cbuf, int off, int len) throws IOException
readreads from the underlyingRandomAccessFileinto an array.- Specified by:
readin classReader- 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:
IOException- if an error occurs.
-
getFilePointer
public long getFilePointer() throws IOException
getFilePointerreturns the effective position of the pointer in the underlyingRandomAccessFile.- Returns:
- a
longoffset. - Throws:
IOException- if an error occurs.
-
seek
public void seek(long pos) throws IOException
seekmoves the pointer to the specified position.- Parameters:
pos- alongoffset.- Throws:
IOException- if an error occurs.
-
-