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 Reader
s from
RandomAccessFile
s.- Since:
- 1.2
- Author:
- Keith James
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newRandomAccessReader
wrapping theRandomAccessFile
and using a default-sized buffer (8192 bytes).RandomAccessReader
(RandomAccessFile raf, int sz) Creates a newRandomAccessReader
wrapping theRandomAccessFile
and using a buffer of the specified size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
close
closes the underlyingRandomAccessFile
.long
getFilePointer
returns the effective position of the pointer in the underlyingRandomAccessFile
.long
length()
length
returns the length of the underlyingRandomAccessFile
.final int
read()
read
reads one byte from the underlyingRandomAccessFile
.int
read
(char[] cbuf, int off, int len) read
reads from the underlyingRandomAccessFile
into an array.void
seek
(long pos) seek
moves 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 newRandomAccessReader
wrapping theRandomAccessFile
and using a default-sized buffer (8192 bytes).- Parameters:
raf
- aRandomAccessFile
to wrap.- Throws:
IOException
- if an error occurs.
-
RandomAccessReader
Creates a newRandomAccessReader
wrapping theRandomAccessFile
and using a buffer of the specified size.- Parameters:
raf
- aRandomAccessFile
to wrap.sz
- anint
buffer size.- Throws:
IOException
-
-
Method Details
-
close
close
closes the underlyingRandomAccessFile
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
- if an error occurs.
-
length
length
returns the length of the underlyingRandomAccessFile
.- Returns:
- a
long
. - Throws:
IOException
- if an error occurs.
-
read
read
reads one byte from the underlyingRandomAccessFile
.- Overrides:
read
in classReader
- Returns:
- an
int
, -1 if the end of the stream has been reached. - Throws:
IOException
- if an error occurs.
-
read
read
reads from the underlyingRandomAccessFile
into an array.- Specified by:
read
in classReader
- Parameters:
cbuf
- achar []
array to read into.off
- anint
offset in the array at which to start storing chars.len
- anint
maximum number of char to read.- Returns:
- an
int
number of chars read, or -1 if the end of the stream has been reached. - Throws:
IOException
- if an error occurs.
-
getFilePointer
getFilePointer
returns the effective position of the pointer in the underlyingRandomAccessFile
.- Returns:
- a
long
offset. - Throws:
IOException
- if an error occurs.
-
seek
seek
moves the pointer to the specified position.- Parameters:
pos
- along
offset.- Throws:
IOException
- if an error occurs.
-