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
RandomAccessReader
extendsReader
to provide a means to create bufferedReader
s fromRandomAccessFile
s.- Since:
- 1.2
- Author:
- Keith James
-
-
Constructor Summary
Constructors Constructor Description RandomAccessReader(RandomAccessFile raf)
Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
close
closes the underlyingRandomAccessFile
.long
getFilePointer()
getFilePointer
returns the effective position of the pointer in the underlyingRandomAccessFile
.long
length()
length
returns the length of the underlyingRandomAccessFile
.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 Detail
-
RandomAccessReader
public RandomAccessReader(RandomAccessFile raf) throws IOException
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
public RandomAccessReader(RandomAccessFile raf, int sz) throws IOException
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 Detail
-
close
public void close() throws IOException
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
public long length() throws IOException
length
returns the length of the underlyingRandomAccessFile
.- Returns:
- a
long
. - Throws:
IOException
- if an error occurs.
-
read
public final int read() throws IOException
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
public int read(char[] cbuf, int off, int len) throws IOException
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
public long getFilePointer() throws IOException
getFilePointer
returns the effective position of the pointer in the underlyingRandomAccessFile
.- Returns:
- a
long
offset. - Throws:
IOException
- if an error occurs.
-
seek
public void seek(long pos) throws IOException
seek
moves the pointer to the specified position.- Parameters:
pos
- along
offset.- Throws:
IOException
- if an error occurs.
-
-