Package org.apache.pdfbox.io
Class PushBackInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.PushbackInputStream
org.apache.pdfbox.io.PushBackInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
ByteArrayPushBackInputStream
A simple subclass that adds a few convience methods.
- Version:
- $Revision: 1.6 $
- Author:
- Ben Litchfield
-
Field Summary
Fields inherited from class java.io.PushbackInputStream
buf, posFields inherited from class java.io.FilterInputStream
in -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis is a method used to fix PDFBox issue 974661, the PDF parsing code needs to know if there is at least x amount of data left in the stream, but the available() method returns how much data will be available without blocking.longReturns the current byte offset in the file.booleanisEOF()A simple test to see if we are at the end of the stream.intpeek()This will peek at the next byte.intread()intread(byte[] b) intread(byte[] b, int off, int len) byte[]readFully(int length) Reads a given number of bytes from the underlying stream.voidseek(long newOffset) Allows to seek to another position within stream in case the underlying stream implementsRandomAccessRead.voidunread(byte[] b) voidunread(byte[] b, int off, int len) voidunread(int b) Methods inherited from class java.io.PushbackInputStream
available, close, mark, markSupported, reset, skipMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
PushBackInputStream
Constructor.- Parameters:
input- The input stream.size- The size of the push back buffer.- Throws:
IOException- If there is an error with the stream.
-
-
Method Details
-
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.
-
getOffset
public long getOffset()Returns the current byte offset in the file.- Returns:
- the int byte offset
-
read
- Overrides:
readin classPushbackInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
- Overrides:
readin classPushbackInputStream- Throws:
IOException
-
unread
- Overrides:
unreadin classPushbackInputStream- Throws:
IOException
-
unread
- Overrides:
unreadin classPushbackInputStream- Throws:
IOException
-
unread
- Overrides:
unreadin classPushbackInputStream- Throws:
IOException
-
isEOF
A simple test to see if we are at the end of the stream.- Returns:
- true if we are at the end of the stream.
- Throws:
IOException- If there is an error reading the next byte.
-
fillBuffer
This is a method used to fix PDFBox issue 974661, the PDF parsing code needs to know if there is at least x amount of data left in the stream, but the available() method returns how much data will be available without blocking. PDFBox is willing to block to read the data, so we will first fill the internal buffer.- Throws:
IOException- If there is an error filling the buffer.
-
readFully
Reads a given number of bytes from the underlying stream.- Parameters:
length- the number of bytes to be read- Returns:
- a byte array containing the bytes just read
- Throws:
IOException- if an I/O error occurs while reading data
-
seek
Allows to seek to another position within stream in case the underlying stream implementsRandomAccessRead. Otherwise anIOExceptionis thrown. Pushback buffer is cleared before seek operation by skipping over all bytes of buffer.- Parameters:
newOffset- new position within stream from which to read next- Throws:
IOException- if underlying stream does not implementRandomAccessReador seek operation on underlying stream was not successful
-