Package org.apache.pdfbox.io
Class RandomAccessBuffer
java.lang.Object
org.apache.pdfbox.io.RandomAccessBuffer
- All Implemented Interfaces:
Closeable
,AutoCloseable
,RandomAccess
,RandomAccessRead
,SequentialRead
An implementation of the RandomAccess interface to store a pdf in memory.
The data will be stored in 16kb chunks organized in an ArrayList.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
void
close()
Release resources that are being held.long
Returns offset of next byte to be returned by a read method.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.void
seek
(long position) Seek to a position in the data.void
write
(byte[] b, int offset, int length) Write a buffer of data to the stream.void
write
(int b) Write a byte to the stream.
-
Constructor Details
-
RandomAccessBuffer
public RandomAccessBuffer()Default constructor.
-
-
Method Details
-
clone
-
close
Release resources that are being held.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceSequentialRead
- Throws:
IOException
- If there is an error closing this resource.
-
seek
Seek to a position in the data.- Specified by:
seek
in interfaceRandomAccessRead
- Parameters:
position
- The position to seek to.- Throws:
IOException
- If there is an error while seeking.
-
getPosition
Returns offset of next byte to be returned by a read method.- Specified by:
getPosition
in interfaceRandomAccessRead
- Returns:
- offset of next byte which will be returned with next
SequentialRead.read()
(if no more bytes are left it returns a value >= length of source) - Throws:
IOException
-
read
Read a single byte of data.- Specified by:
read
in interfaceSequentialRead
- Returns:
- The byte of data that is being read.
- Throws:
IOException
- If there is an error while reading the data.
-
read
Read a buffer of data.- Specified by:
read
in interfaceSequentialRead
- Parameters:
b
- The buffer to write the data to.offset
- Offset into the buffer to start writing.length
- The amount of data to attempt to read.- Returns:
- The number of bytes that were actually read.
- Throws:
IOException
- If there was an error while reading the data.
-
length
The total number of bytes that are available.- Specified by:
length
in interfaceRandomAccessRead
- Returns:
- The number of bytes available.
- Throws:
IOException
- If there is an IO error while determining the length of the data stream.
-
write
Write a byte to the stream.- Specified by:
write
in interfaceRandomAccess
- Parameters:
b
- The byte to write.- Throws:
IOException
- If there is an IO error while writing.
-
write
Write a buffer of data to the stream.- Specified by:
write
in interfaceRandomAccess
- Parameters:
b
- The buffer to get the data from.offset
- An offset into the buffer to get the data from.length
- The length of data to write.- Throws:
IOException
- If there is an error while writing the data.
-