public class RandomAccessReadBuffer extends Object implements RandomAccessRead
| Modifier and Type | Field and Description |
|---|---|
protected int |
chunkSize |
protected ByteBuffer |
currentBuffer |
protected int |
currentBufferPointer |
static int |
DEFAULT_CHUNK_SIZE_4KB |
protected long |
pointer |
protected long |
size |
| Modifier | Constructor and Description |
|---|---|
protected |
RandomAccessReadBuffer()
Default constructor.
|
|
RandomAccessReadBuffer(byte[] input)
Create a random access buffer using the given byte array.
|
|
RandomAccessReadBuffer(ByteBuffer input)
Create a random access buffer using the given ByteBuffer.
|
|
RandomAccessReadBuffer(InputStream input)
Create a random access read buffer of the given input stream by copying the data to the memory.
|
protected |
RandomAccessReadBuffer(int definedChunkSize)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkClosed()
Ensure that the RandomAccessBuffer is not closed
|
void |
close() |
static RandomAccessReadBuffer |
createBufferFromStream(InputStream inputStream)
Create e new RandomAccessReadBuffer using the given InputStream.
|
RandomAccessReadView |
createView(long startPosition,
long streamLength)
Creates a random access read view starting at the given position with the given length.
|
protected void |
expandBuffer()
create a new buffer chunk and adjust all pointers and indices.
|
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 offset,
int length)
Read a buffer of data.
|
protected void |
resetBuffers()
Reset to position 0 and remove all buffers but the first one.
|
void |
seek(long position)
Seek to a position in the data.
|
public static final int DEFAULT_CHUNK_SIZE_4KB
protected int chunkSize
protected ByteBuffer currentBuffer
protected long pointer
protected int currentBufferPointer
protected long size
protected RandomAccessReadBuffer()
protected RandomAccessReadBuffer(int definedChunkSize)
public RandomAccessReadBuffer(byte[] input)
input - the byte array to be readpublic RandomAccessReadBuffer(ByteBuffer input)
input - the ByteBuffer to be readpublic RandomAccessReadBuffer(InputStream input) throws IOException
input - the input stream to be readIOException - if something went wrong while copying the datapublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic void seek(long position)
throws IOException
seek in interface RandomAccessReadposition - The position to seek to.IOException - If there is an error while seeking.public long getPosition()
throws IOException
getPosition in interface RandomAccessReadRandomAccessRead.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 int read()
throws IOException
read in interface RandomAccessReadIOException - If there is an error while reading the data.public int read(byte[] b,
int offset,
int length)
throws IOException
read in interface RandomAccessReadb - The buffer to write the data to.offset - Offset into the buffer to start writing.length - 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 RandomAccessReadIOException - If there is an IO error while determining the length of the data stream.protected void expandBuffer()
throws IOException
IOExceptionprotected void checkClosed()
throws IOException
IOException - If RandomAccessBuffer already closedpublic boolean isClosed()
isClosed in interface RandomAccessReadpublic boolean isEOF()
throws IOException
isEOF in interface RandomAccessReadIOException - If there is an error reading the next byte.public RandomAccessReadView createView(long startPosition, long streamLength) throws IOException
RandomAccessReadcreateView in interface RandomAccessReadstartPosition - start position within the underlying random access readstreamLength - stream lengthIOException - if something went wrong when creating the view for the RandomAccessReadpublic static RandomAccessReadBuffer createBufferFromStream(InputStream inputStream) throws IOException
inputStream - the InputStream holding the data to be copiedIOException - if something went wrong while copying the dataprotected void resetBuffers()
Copyright © 2002–2025 The Apache Software Foundation. All rights reserved.