Package org.apache.pdfbox.io
Interface RandomAccessRead
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Subinterfaces:
RandomAccess
- All Known Implementing Classes:
NonSeekableRandomAccessReadInputStream,RandomAccessReadBuffer,RandomAccessReadBufferedFile,RandomAccessReadMemoryMappedFile,RandomAccessReadView,RandomAccessReadWriteBuffer,ScratchFileBuffer,SequenceRandomAccessRead
An interface allowing random access read operations.
-
Method Summary
Modifier and TypeMethodDescriptiondefault intReturns an estimate of the number of bytes that can be read.createView(long startPosition, long streamLength) Creates a random access read view starting at the given position with the given length.longReturns 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.default intpeek()This will peek at the next byte.intread()Read a single byte of data.default intread(byte[] b) Read a buffer of data.intread(byte[] b, int offset, int length) Read a buffer of data.default voidreadFully(byte[] b) Same asread(byte[])but will loop until exactly length bytes are read or it will throw an exception.default voidreadFully(byte[] b, int offset, int length) Same asread(byte[], int, int)but will loop until exactly length bytes are read or it will throw an exception.default voidrewind(int bytes) Seek backwards the given number of bytes.voidseek(long position) Seek to a position in the data.default voidskip(int length) Skips a given number of bytes.
-
Method Details
-
read
Read a single byte of data.- 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.- Parameters:
b- The buffer to write the data to.- Returns:
- The number of bytes that were actually read.
- Throws:
IOException- If there was an error while reading the data.
-
read
Read a buffer of data.- 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
Returns offset of next byte to be returned by a read method.- Returns:
- offset of next byte which will be returned with next
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
Seek to a position in the data.- Parameters:
position- The position to seek to.- Throws:
IOException- If there is an error while seeking.
-
length
The total number of bytes that are available.- Returns:
- The number of bytes available.
- Throws:
IOException- If there is an IO error while determining the length of the data stream.
-
isClosed
boolean isClosed()Returns true if this source has been closed.- Returns:
- true if the source has been closed
-
peek
This will peek at the next byte.- Returns:
- The next byte on the stream, leaving it as available to read.
- Throws:
IOException- If there is an error reading the next byte.
-
rewind
Seek backwards the given number of bytes.- Parameters:
bytes- the number of bytes to be seeked backwards- Throws:
IOException- If there is an error while seeking
-
isEOF
A simple test to see if we are at the end of the data.- Returns:
- true if we are at the end of the data.
- Throws:
IOException- If there is an error reading the next byte.
-
available
Returns an estimate of the number of bytes that can be read.- Returns:
- the number of bytes that can be read
- Throws:
IOException- if this random access has been closed
-
skip
Skips a given number of bytes.- Parameters:
length- the number of bytes to be skipped- Throws:
IOException- if an I/O error occurs while reading data
-
createView
Creates a random access read view starting at the given position with the given length.- 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
-
readFully
Same asread(byte[])but will loop until exactly length bytes are read or it will throw an exception.- Parameters:
b- The buffer to write the data to.- Throws:
IOException
-
readFully
Same asread(byte[], int, int)but will loop until exactly length bytes are read or it will throw an exception.- Parameters:
b- The buffer to write the data to.offset- Offset into the buffer to start writing.length- The exact amount of data to attempt to read.- Throws:
IOException
-