org.apache.pdfbox.io
Class PushBackInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.PushbackInputStream
              extended by org.apache.pdfbox.io.PushBackInputStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
ByteArrayPushBackInputStream

public class PushBackInputStream
extends PushbackInputStream

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, pos
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
PushBackInputStream(InputStream input, int size)
          Constructor.
 
Method Summary
 void 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.
 int getOffset()
          Returns the current byte offset in the file.
 boolean isEOF()
          A simple test to see if we are at the end of the stream.
 int peek()
          This will peek at the next byte.
 int read()
          
 int read(byte[] b)
          
 int read(byte[] b, int off, int len)
          
 byte[] readFully(int length)
          Reads a given number of bytes from the underlying stream.
 void unread(byte[] b)
          
 void unread(byte[] b, int off, int len)
          
 void unread(int b)
          
 
Methods inherited from class java.io.PushbackInputStream
available, close, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PushBackInputStream

public PushBackInputStream(InputStream input,
                           int size)
                    throws IOException
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 Detail

peek

public int peek()
         throws IOException
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 int getOffset()
Returns the current byte offset in the file.

Returns:
the int byte offset

read

public int read()
         throws IOException

Overrides:
read in class PushbackInputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException

Overrides:
read in class FilterInputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException

Overrides:
read in class PushbackInputStream
Throws:
IOException

unread

public void unread(int b)
            throws IOException

Overrides:
unread in class PushbackInputStream
Throws:
IOException

unread

public void unread(byte[] b)
            throws IOException

Overrides:
unread in class PushbackInputStream
Throws:
IOException

unread

public void unread(byte[] b,
                   int off,
                   int len)
            throws IOException

Overrides:
unread in class PushbackInputStream
Throws:
IOException

isEOF

public boolean isEOF()
              throws IOException
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

public void fillBuffer()
                throws IOException
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

public byte[] readFully(int length)
                 throws IOException
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


Copyright © 2002-2012 Apache Software Foundation. All Rights Reserved.