Package org.apache.pdfbox.io
Class SequenceRandomAccessRead
java.lang.Object
org.apache.pdfbox.io.SequenceRandomAccessRead
- All Implemented Interfaces:
Closeable,AutoCloseable,RandomAccessRead
Wrapper class to combine several RandomAccessRead instances so that they can be accessed as one big RandomAccessRead.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate longprivate RandomAccessReadprivate final long[]private booleanprivate final intprivate final List<RandomAccessRead> private final long[]private long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidEnsure that the SequenceRandomAccessRead is not closedvoidclose()createView(long startPosition, long streamLength) Creates a random access read view starting at the given position with the given length.private RandomAccessReadlongReturns offset of next byte to be returned by a read method.booleanisClosed()Returns true if this source has been closed.booleanisEOF()A simple test to see if we are at the end of the data.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.
-
Field Details
-
readerList
-
startPositions
private final long[] startPositions -
endPositions
private final long[] endPositions -
numberOfReader
private final int numberOfReader -
currentIndex
private int currentIndex -
currentPosition
private long currentPosition -
totalLength
private long totalLength -
isClosed
private boolean isClosed -
currentRandomAccessRead
-
-
Constructor Details
-
SequenceRandomAccessRead
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getCurrentReader
- Throws:
IOException
-
read
Description copied from interface:RandomAccessReadRead a single byte of data.- Specified by:
readin interfaceRandomAccessRead- Returns:
- The byte of data that is being read.
- Throws:
IOException- If there is an error while reading the data.
-
read
Description copied from interface:RandomAccessReadRead a buffer of data.- Specified by:
readin interfaceRandomAccessRead- 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.
-
getPosition
Description copied from interface:RandomAccessReadReturns 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
RandomAccessRead.read()(if no more bytes are left it returns a value >= length of source) - Throws:
IOException- If there was an error while getting the current position
-
seek
Description copied from interface:RandomAccessReadSeek to a position in the data.- Specified by:
seekin interfaceRandomAccessRead- Parameters:
position- The position to seek to.- Throws:
IOException- If there is an error while seeking.
-
length
Description copied from interface:RandomAccessReadThe total number of bytes that are available.- Specified by:
lengthin interfaceRandomAccessRead- Returns:
- The number of bytes available.
- Throws:
IOException- If there is an IO error while determining the length of the data stream.
-
isClosed
public boolean isClosed()Description copied from interface:RandomAccessReadReturns true if this source has been closed.- Specified by:
isClosedin interfaceRandomAccessRead- Returns:
- true if the source has been closed
-
checkClosed
Ensure that the SequenceRandomAccessRead is not closed- Throws:
IOException- If RandomAccessBuffer already closed
-
isEOF
Description copied from interface:RandomAccessReadA simple test to see if we are at the end of the data.- Specified by:
isEOFin interfaceRandomAccessRead- Returns:
- true if we are at the end of the data.
- Throws:
IOException- If there is an error reading the next byte.
-
createView
Description copied from interface:RandomAccessReadCreates a random access read view starting at the given position with the given length.- Specified by:
createViewin interfaceRandomAccessRead- Parameters:
startPosition- start position within the underlying random access readstreamLength- stream length- Returns:
- the random access read view
- Throws:
IOException- if something went wrong when creating the view for the RandomAccessRead
-