Package org.apache.pdfbox.pdfparser
Class RandomAccessSource
- java.lang.Object
-
- org.apache.pdfbox.pdfparser.RandomAccessSource
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SequentialSource
final class RandomAccessSource extends java.lang.Object implements SequentialSource
A SequentialSource backed by a RandomAccessRead.
-
-
Field Summary
Fields Modifier and Type Field Description private RandomAccessReadreader
-
Constructor Summary
Constructors Constructor Description RandomAccessSource(RandomAccessRead reader)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longgetPosition()Returns offset of next byte to be returned by a read method.booleanisEOF()Returns true if the end of the data source has been reached.intpeek()This will peek at the next byte.intread()Read a single byte of data.intread(byte[] b)Read a buffer of data.intread(byte[] b, int offset, int length)Read a buffer of data.byte[]readFully(int length)Reads a given number of bytes in its entirety.voidunread(byte[] bytes)Unreads an array of bytes.voidunread(byte[] bytes, int start, int len)Unreads a portion of an array of bytes.voidunread(int b)Unreads a single byte.
-
-
-
Field Detail
-
reader
private final RandomAccessRead reader
-
-
Constructor Detail
-
RandomAccessSource
RandomAccessSource(RandomAccessRead reader)
Constructor.- Parameters:
reader- The random access reader to wrap.
-
-
Method Detail
-
read
public int read() throws java.io.IOExceptionDescription copied from interface:SequentialSourceRead a single byte of data.- Specified by:
readin interfaceSequentialSource- 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) throws java.io.IOExceptionDescription copied from interface:SequentialSourceRead a buffer of data.- Specified by:
readin interfaceSequentialSource- Parameters:
b- The buffer to write the data to.- Returns:
- The number of bytes that were actually read.
- Throws:
java.io.IOException- If there was an error while reading the data.
-
read
public int read(byte[] b, int offset, int length) throws java.io.IOExceptionDescription copied from interface:SequentialSourceRead a buffer of data.- Specified by:
readin interfaceSequentialSource- 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.
-
getPosition
public long getPosition() throws java.io.IOExceptionDescription copied from interface:SequentialSourceReturns offset of next byte to be returned by a read method.- Specified by:
getPositionin interfaceSequentialSource- Returns:
- offset of next byte which will be returned with next
SequentialSource.read()(if no more bytes are left it returns a value >= length of source). - Throws:
java.io.IOException- If there was an error while reading the data.
-
peek
public int peek() throws java.io.IOExceptionDescription copied from interface:SequentialSourceThis will peek at the next byte.- Specified by:
peekin interfaceSequentialSource- Returns:
- The next byte on the stream, leaving it as available to read.
- Throws:
java.io.IOException- If there is an error reading the next byte.
-
unread
public void unread(int b) throws java.io.IOExceptionDescription copied from interface:SequentialSourceUnreads a single byte.- Specified by:
unreadin interfaceSequentialSource- Parameters:
b- byte array to push back- Throws:
java.io.IOException- if there is an error while unreading
-
unread
public void unread(byte[] bytes) throws java.io.IOExceptionDescription copied from interface:SequentialSourceUnreads an array of bytes.- Specified by:
unreadin interfaceSequentialSource- Parameters:
bytes- byte array to be unread- Throws:
java.io.IOException- if there is an error while unreading
-
unread
public void unread(byte[] bytes, int start, int len) throws java.io.IOExceptionDescription copied from interface:SequentialSourceUnreads a portion of an array of bytes.- Specified by:
unreadin interfaceSequentialSource- Parameters:
bytes- byte array to be unreadstart- start indexlen- number of bytes to be unread- Throws:
java.io.IOException- if there is an error while unreading
-
readFully
public byte[] readFully(int length) throws java.io.IOExceptionDescription copied from interface:SequentialSourceReads a given number of bytes in its entirety.- Specified by:
readFullyin interfaceSequentialSource- Parameters:
length- the number of bytes to be read- Returns:
- a byte array containing the bytes just read
- Throws:
java.io.IOException- if an I/O error occurs while reading data
-
isEOF
public boolean isEOF() throws java.io.IOExceptionDescription copied from interface:SequentialSourceReturns true if the end of the data source has been reached.- Specified by:
isEOFin interfaceSequentialSource- Returns:
- true if we are at the end of the data.
- Throws:
java.io.IOException- If there is an error reading the next byte.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-