org.eclipse.ercp.xml.io
Class SimpleBufferedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.eclipse.ercp.xml.io.SimpleBufferedInputStream
All Implemented Interfaces:
java.io.Closeable

public class SimpleBufferedInputStream
extends java.io.InputStream

Simplified version of a BufferedInputStream allowing to rewind read bytes by providing them!


Constructor Summary
SimpleBufferedInputStream(java.io.InputStream in)
          Constructor for SimpleBufferedInputStream.
 
Method Summary
 int available()
          Answers a int representing then number of bytes that are available before this InputStream will block.
 void close()
          Close the InputStream.
 int read()
          Reads a single byte from this InputStream and returns the result as an int.
 int read(byte[] buffer, int offset, int length)
          Reads at most length bytes from this InputStream and stores them in byte array buffer starting at offset offset.
 long skip(long amount)
          Skips amount number of bytes in this BufferedInputStream.
 void unread(byte[] bytes, int length)
          Restore a set of bytes in the buffer
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleBufferedInputStream

public SimpleBufferedInputStream(java.io.InputStream in)
                          throws java.io.IOException
Constructor for SimpleBufferedInputStream.

Throws:
java.io.IOException
Method Detail

read

public int read()
         throws java.io.IOException
Reads a single byte from this InputStream and returns the result as an int. The low-order byte is returned or -1 of the end of stream was encountered. If the underlying buffer does not contain any available bytes then it is filled and the first byte is returned.

Specified by:
read in class java.io.InputStream
Returns:
the byte read or -1 if end of stream.
Throws:
java.io.IOException - If the stream is already closed or another IOException occurs.

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws java.io.IOException
Reads at most length bytes from this InputStream and stores them in byte array buffer starting at offset offset. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered. If all the buffered bytes have been used, a mark has not been set, and the requested number of bytes is larger than the receiver's buffer size, this implementation bypasses the buffer and simply places the results directly into buffer.

Overrides:
read in class java.io.InputStream
Parameters:
buffer - the byte array in which to store the read bytes.
offset - the offset in buffer to store the read bytes.
length - the maximum number of bytes to store in buffer.
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
java.io.IOException - If the stream is already closed or another IOException occurs.

unread

public void unread(byte[] bytes,
                   int length)
Restore a set of bytes in the buffer


close

public void close()
           throws java.io.IOException
Close the InputStream. Concrete implementations of this class should free any resources during close. This implementation does nothing.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - If an error occurs attempting to close this InputStream.

available

public int available()
              throws java.io.IOException
Answers a int representing then number of bytes that are available before this InputStream will block. This method always returns 0. Subclasses should override and indicate the correct number of bytes available.

Overrides:
available in class java.io.InputStream
Returns:
the number of bytes available before blocking.
Throws:
java.io.IOException - If an error occurs in this InputStream.

skip

public long skip(long amount)
          throws java.io.IOException
Skips amount number of bytes in this BufferedInputStream. Subsequent read()'s will not return these bytes unless reset() is used.

Overrides:
skip in class java.io.InputStream
Parameters:
amount - the number of bytes to skip.
Returns:
the number of bytes actually skipped.
Throws:
java.io.IOException - If the stream is already closed or another IOException occurs.