public class RandomAccessReadView extends Object implements RandomAccessRead
Constructor and Description |
---|
RandomAccessReadView(RandomAccessRead randomAccessRead,
long startPosition,
long streamLength)
Constructor.
|
RandomAccessReadView(RandomAccessRead randomAccessRead,
long startPosition,
long streamLength,
boolean closeInput)
Constructor.
|
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 |
rewind(int bytes)
Seek backwards the given number of bytes.
|
void |
seek(long newOffset)
Seek to a position in the data.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
available, peek, read, skip
public RandomAccessReadView(RandomAccessRead randomAccessRead, long startPosition, long streamLength)
randomAccessRead
- the underlying random access readstartPosition
- start position within the underlying random access readstreamLength
- stream lengthpublic RandomAccessReadView(RandomAccessRead randomAccessRead, long startPosition, long streamLength, boolean closeInput)
randomAccessRead
- the underlying random access readstartPosition
- start position within the underlying random access readstreamLength
- stream lengthcloseInput
- close the underlying random access read when closing the view if set to truepublic long getPosition() throws IOException
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 newOffset) throws IOException
seek
in interface RandomAccessRead
newOffset
- The position to seek to.IOException
- If there is an error while seeking.public int read() throws IOException
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
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
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()
isClosed
in interface RandomAccessRead
public void rewind(int bytes) throws IOException
rewind
in interface RandomAccessRead
bytes
- the number of bytes to be seeked backwardsIOException
- If there is an error while seekingpublic boolean isEOF() throws IOException
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–2023 The Apache Software Foundation. All rights reserved.