public class RandomAccessReader
extends java.io.Reader
RandomAccessReader extends Reader to
provide a means to create buffered Readers from
RandomAccessFiles.| Constructor and Description |
|---|
RandomAccessReader(java.io.RandomAccessFile raf)
Creates a new
RandomAccessReader wrapping the
RandomAccessFile and using a default-sized buffer
(8192 bytes). |
RandomAccessReader(java.io.RandomAccessFile raf,
int sz)
Creates a new
RandomAccessReader wrapping the
RandomAccessFile and using a buffer of the
specified size. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
close closes the underlying
RandomAccessFile. |
long |
getFilePointer()
getFilePointer returns the effective position of
the pointer in the underlying RandomAccessFile. |
long |
length()
length returns the length of the underlying
RandomAccessFile. |
int |
read()
read reads one byte from the underlying
RandomAccessFile. |
int |
read(char[] cbuf,
int off,
int len)
read reads from the underlying
RandomAccessFile into an array. |
void |
seek(long pos)
seek moves the pointer to the specified position. |
public RandomAccessReader(java.io.RandomAccessFile raf)
throws java.io.IOException
RandomAccessReader wrapping the
RandomAccessFile and using a default-sized buffer
(8192 bytes).raf - a RandomAccessFile to wrap.java.io.IOException - if an error occurs.public RandomAccessReader(java.io.RandomAccessFile raf,
int sz)
throws java.io.IOException
RandomAccessReader wrapping the
RandomAccessFile and using a buffer of the
specified size.raf - a RandomAccessFile to wrap.sz - an int buffer size.java.io.IOExceptionpublic void close()
throws java.io.IOException
close closes the underlying
RandomAccessFile.close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Readerjava.io.IOException - if an error occurs.public long length()
throws java.io.IOException
length returns the length of the underlying
RandomAccessFile.long.java.io.IOException - if an error occurs.public final int read()
throws java.io.IOException
read reads one byte from the underlying
RandomAccessFile.read in class java.io.Readerint, -1 if the end of the stream has
been reached.java.io.IOException - if an error occurs.public int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
read reads from the underlying
RandomAccessFile into an array.read in class java.io.Readercbuf - a char [] array to read into.off - an int offset in the array at which to
start storing chars.len - an int maximum number of char to read.int number of chars read, or -1 if the
end of the stream has been reached.java.io.IOException - if an error occurs.public long getFilePointer()
throws java.io.IOException
getFilePointer returns the effective position of
the pointer in the underlying RandomAccessFile.long offset.java.io.IOException - if an error occurs.public void seek(long pos)
throws java.io.IOException
seek moves the pointer to the specified position.pos - a long offset.java.io.IOException - if an error occurs.