public class RandomAccessReadBufferedFile extends Object implements RandomAccessRead
FileChannel
and is read in ByteBuffer chunks which are cached.Constructor and Description |
---|
RandomAccessReadBufferedFile(File file)
Create a random access buffered file instance for the given file.
|
RandomAccessReadBufferedFile(String filename)
Create a random access buffered file instance for the file with the given name.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
RandomAccessReadView |
createView(long startPosition,
long streamLength)
Creates a random access read view starting at the given position with the given length.
|
long |
getPosition()
Returns offset of next byte to be returned by a read method.
|
boolean |
isClosed()
Returns true if this source has been closed.
|
boolean |
isEOF()
A simple test to see if we are at the end of the data.
|
long |
length()
The total number of bytes that are available.
|
int |
read()
Read a single byte of data.
|
int |
read(byte[] b,
int off,
int len)
Read a buffer of data.
|
void |
seek(long position)
Seeks to new position.
|
public RandomAccessReadBufferedFile(String filename) throws IOException
filename
- the filename of the file to be read.IOException
- if something went wrong while accessing the given file.public RandomAccessReadBufferedFile(File file) throws IOException
file
- the file to be read.IOException
- if something went wrong while accessing the given file.public long getPosition() throws IOException
RandomAccessRead
getPosition
in interface RandomAccessRead
RandomAccessRead.read()
(if no more bytes are left it
returns a value >= length of source)IOException
- If there was an error while getting the current positionpublic void seek(long position) throws IOException
seek
in interface RandomAccessRead
position
- the position to seek to.IOException
- if something went wrong.public int read() throws IOException
RandomAccessRead
read
in interface RandomAccessRead
IOException
- If there is an error while reading the data.public int read(byte[] b, int off, int len) throws IOException
RandomAccessRead
read
in interface RandomAccessRead
b
- The buffer to write the data to.off
- Offset into the buffer to start writing.len
- The amount of data to attempt to read.IOException
- If there was an error while reading the data.public long length() throws IOException
RandomAccessRead
length
in interface RandomAccessRead
IOException
- If there is an IO error while determining the length of the data stream.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public boolean isClosed()
RandomAccessRead
isClosed
in interface RandomAccessRead
public boolean isEOF() throws IOException
RandomAccessRead
isEOF
in interface RandomAccessRead
IOException
- If there is an error reading the next byte.public RandomAccessReadView createView(long startPosition, long streamLength) throws IOException
RandomAccessRead
createView
in interface RandomAccessRead
startPosition
- start position within the underlying random access readstreamLength
- stream lengthIOException
- if something went wrong when creating the view for the RandomAccessReadCopyright © 2002–2022 The Apache Software Foundation. All rights reserved.