Package com.itextpdf.text.io
Class ByteBufferRandomAccessSource
java.lang.Object
com.itextpdf.text.io.ByteBufferRandomAccessSource
- All Implemented Interfaces:
RandomAccessSource
A RandomAccessSource that is based on an underlying
ByteBuffer. This class takes steps to ensure that the byte buffer
is completely freed from memory during close()- Since:
- 5.3.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteBufferInternal cache of memory mapped buffers -
Constructor Summary
ConstructorsConstructorDescriptionByteBufferRandomAccessSource(ByteBuffer byteBuffer) Constructs a newByteBufferRandomAccessSourcebased on the specified ByteBuffer -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanclean(ByteBuffer buffer) invokes the clean method on the ByteBuffer's cleanervoidclose()Closes this source.intget(long position) Gets a byte at the specified positionintget(long position, byte[] bytes, int off, int len) Gets an array at the specified position.longlength()
-
Field Details
-
byteBuffer
Internal cache of memory mapped buffers
-
-
Constructor Details
-
ByteBufferRandomAccessSource
Constructs a newByteBufferRandomAccessSourcebased on the specified ByteBuffer- Parameters:
byteBuffer- the buffer to use as the backing store
-
-
Method Details
-
get
Gets a byte at the specified positionNote: Because ByteBuffers don't support long indexing, the position must be a valid positive int
- Specified by:
getin interfaceRandomAccessSource- Parameters:
position- the position to read the byte from - must be less than Integer.MAX_VALUE- Returns:
- the byte, or -1 if EOF is reached
- Throws:
IOException
-
get
Gets an array at the specified position. If the number of bytes requested cannot be read, the bytes that can be read will be placed in bytes and the number actually read will be returned.Note: Because ByteBuffers don't support long indexing, the position must be a valid positive int
- Specified by:
getin interfaceRandomAccessSource- Parameters:
position- the position to read the byte from - must be less than Integer.MAX_VALUEbytes- output bufferoff- offset into the output buffer where results will be placedlen- the number of bytes to read- Returns:
- the number of bytes actually read, or -1 if the file is at EOF
- Throws:
IOException
-
length
public long length()- Specified by:
lengthin interfaceRandomAccessSource- Returns:
- the length of this source
-
close
Description copied from interface:RandomAccessSourceCloses this source. The underlying data structure or source (if any) will also be closed- Specified by:
closein interfaceRandomAccessSource- Throws:
IOException- See Also:
-
clean
invokes the clean method on the ByteBuffer's cleaner- Parameters:
buffer- ByteBuffer- Returns:
- boolean true on success
-