org.blinkenbyte.io
Class ReadWriteDevice.RWDInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.blinkenbyte.io.ReadWriteDevice.RWDInputStream
All Implemented Interfaces:
java.io.Closeable
Enclosing interface:
ReadWriteDevice

public static class ReadWriteDevice.RWDInputStream
extends java.io.InputStream

Implementation of an InputStream wrapped around a ReadWriteDevice.


Field Summary
protected  boolean isClosed
          Flag indicating if this stream has been closed.
 ReadWriteDevice rwd
          The ReadWriteDevice being wrapped.
 
Constructor Summary
ReadWriteDevice.RWDInputStream(ReadWriteDevice _rwd)
          Constructs a new RWDInputStream from a ReadWriteDevice.
 
Method Summary
 int available()
          Returns the number of bytes available to be read without blocking.
 void close()
          Closes this stream (but not the underlying ReadWriteDevice).
 void mark(int readLimit)
          Marks the input stream.
 boolean markSupported()
          Returns whether the ReadWriteDevice being wrapped supports mark.
 int read()
          Reads a byte from the underlying ReadWriteDevice.
 int read(byte[] b)
          Reads up to b.length bytes from the device into array b.
 int read(byte[] b, int offset, int len)
          Reads up to len bytes from the device into array b at b[offset].
 void reset()
          Resets the stream to the mark.
 long skip(long n)
          Skips n bytes from the stream.
protected  void throwIfClosed()
          Convenience method to throw an exception if the stream has been closed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rwd

public ReadWriteDevice rwd
The ReadWriteDevice being wrapped.


isClosed

protected boolean isClosed
Flag indicating if this stream has been closed.

Constructor Detail

ReadWriteDevice.RWDInputStream

public ReadWriteDevice.RWDInputStream(ReadWriteDevice _rwd)
Constructs a new RWDInputStream from a ReadWriteDevice.

Method Detail

throwIfClosed

protected void throwIfClosed()
                      throws java.io.IOException
Convenience method to throw an exception if the stream has been closed.

Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException
Returns the number of bytes available to be read without blocking.

Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes this stream (but not the underlying ReadWriteDevice).

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

mark

public void mark(int readLimit)
Marks the input stream.

Overrides:
mark in class java.io.InputStream

markSupported

public boolean markSupported()
Returns whether the ReadWriteDevice being wrapped supports mark.

Overrides:
markSupported in class java.io.InputStream

read

public int read()
         throws java.io.IOException
Reads a byte from the underlying ReadWriteDevice. Returns -1 if end-of-stream.

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Reads up to b.length bytes from the device into array b. Returns the number of bytes read, -1 if currently at end-of-stream.

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b,
                int offset,
                int len)
         throws java.io.IOException
Reads up to len bytes from the device into array b at b[offset]. Returns the number of bytes read, -1 if currently at end-of-stream.

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException
Resets the stream to the mark.

Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Skips n bytes from the stream.

Overrides:
skip in class java.io.InputStream
Throws:
java.io.IOException