Package org.biojava.utils.io
Class RandomAccessReader
java.lang.Object
java.io.Reader
org.biojava.utils.io.RandomAccessReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable
RandomAccessReader extends Reader to
provide a means to create buffered Readers from
RandomAccessFiles.- Since:
- 1.2
- Author:
- Keith James
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoidclose()closecloses the underlyingRandomAccessFile.longgetFilePointerreturns the effective position of the pointer in the underlyingRandomAccessFile.longlength()lengthreturns the length of the underlyingRandomAccessFile.final 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 Details
-
RandomAccessReader
Creates a newRandomAccessReaderwrapping theRandomAccessFileand using a default-sized buffer (8192 bytes).- Parameters:
raf- aRandomAccessFileto wrap.- Throws:
IOException- if an error occurs.
-
RandomAccessReader
Creates a newRandomAccessReaderwrapping theRandomAccessFileand using a buffer of the specified size.- Parameters:
raf- aRandomAccessFileto wrap.sz- anintbuffer size.- Throws:
IOException
-
-
Method Details
-
close
closecloses the underlyingRandomAccessFile.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException- if an error occurs.
-
length
lengthreturns the length of the underlyingRandomAccessFile.- Returns:
- a
long. - Throws:
IOException- if an error occurs.
-
read
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
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
getFilePointerreturns the effective position of the pointer in the underlyingRandomAccessFile.- Returns:
- a
longoffset. - Throws:
IOException- if an error occurs.
-
seek
seekmoves the pointer to the specified position.- Parameters:
pos- alongoffset.- Throws:
IOException- if an error occurs.
-