Package org.apache.pdfbox.io
Class RandomAccessBuffer
- java.lang.Object
-
- org.apache.pdfbox.io.RandomAccessBuffer
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,RandomAccess,RandomAccessRead,SequentialRead
public class RandomAccessBuffer extends java.lang.Object implements RandomAccess, java.io.Closeable
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 Constructor Description RandomAccessBuffer()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RandomAccessBufferclone()voidclose()Release resources that are being held.longgetPosition()Returns offset of next byte to be returned by a read method.longlength()The total number of bytes that are available.intread()Read a single byte of data.intread(byte[] b, int offset, int length)Read a buffer of data.voidseek(long position)Seek to a position in the data.voidwrite(byte[] b, int offset, int length)Write a buffer of data to the stream.voidwrite(int b)Write a byte to the stream.
-
-
-
Method Detail
-
clone
public RandomAccessBuffer clone()
- Overrides:
clonein classjava.lang.Object
-
close
public void close() throws java.io.IOExceptionRelease resources that are being held.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceSequentialRead- Throws:
java.io.IOException- If there is an error closing this resource.
-
seek
public void seek(long position) throws java.io.IOExceptionSeek to a position in the data.- Specified by:
seekin interfaceRandomAccessRead- Parameters:
position- The position to seek to.- Throws:
java.io.IOException- If there is an error while seeking.
-
getPosition
public long getPosition() throws java.io.IOExceptionReturns offset of next byte to be returned by a read method.- Specified by:
getPositionin 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:
java.io.IOException
-
read
public int read() throws java.io.IOExceptionRead a single byte of data.- Specified by:
readin interfaceSequentialRead- Returns:
- The byte of data that is being read.
- Throws:
java.io.IOException- If there is an error while reading the data.
-
read
public int read(byte[] b, int offset, int length) throws java.io.IOExceptionRead a buffer of data.- Specified by:
readin 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:
java.io.IOException- If there was an error while reading the data.
-
length
public long length() throws java.io.IOExceptionThe total number of bytes that are available.- Specified by:
lengthin interfaceRandomAccessRead- Returns:
- The number of bytes available.
- Throws:
java.io.IOException- If there is an IO error while determining the length of the data stream.
-
write
public void write(int b) throws java.io.IOExceptionWrite a byte to the stream.- Specified by:
writein interfaceRandomAccess- Parameters:
b- The byte to write.- Throws:
java.io.IOException- If there is an IO error while writing.
-
write
public void write(byte[] b, int offset, int length) throws java.io.IOExceptionWrite a buffer of data to the stream.- Specified by:
writein 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:
java.io.IOException- If there is an error while writing the data.
-
-