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 ByteBuffer
Internal cache of memory mapped buffers -
Constructor Summary
ConstructorsConstructorDescriptionByteBufferRandomAccessSource
(ByteBuffer byteBuffer) Constructs a newByteBufferRandomAccessSource
based on the specified ByteBuffer -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
clean
(ByteBuffer buffer) invokes the clean method on the ByteBuffer's cleanervoid
close()
Closes this source.int
get
(long position) Gets a byte at the specified positionint
get
(long position, byte[] bytes, int off, int len) Gets an array at the specified position.long
length()
-
Field Details
-
byteBuffer
Internal cache of memory mapped buffers
-
-
Constructor Details
-
ByteBufferRandomAccessSource
Constructs a newByteBufferRandomAccessSource
based 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:
get
in 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:
get
in 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:
length
in interfaceRandomAccessSource
- Returns:
- the length of this source
-
close
Description copied from interface:RandomAccessSource
Closes this source. The underlying data structure or source (if any) will also be closed- Specified by:
close
in interfaceRandomAccessSource
- Throws:
IOException
- See Also:
-
clean
invokes the clean method on the ByteBuffer's cleaner- Parameters:
buffer
- ByteBuffer- Returns:
- boolean true on success
-