ewe.io
Class PartialInputStream

java.lang.Object
  extended byewe.util.Errorable
      extended byewe.io.BasicStreamObject
          extended byewe.io.StreamObject
              extended byewe.io.StreamAdapter
                  extended byewe.io.PartialInputStream
All Implemented Interfaces:
BasicStream, BufferedStream, Stream, Streamable, StreamCanPause

public class PartialInputStream
extends StreamAdapter

This class is used to get a "sub-stream" of data from another Stream. The partial stream can limit the amount of data which can be read from the original Stream. Note the following:

  • Calling close() on a PartialInputStream does not close the original stream, unless closeUnderlying is true.
  • Setting a limit of -1 will not impose any limit on the number of bytes which can be read.
  • Input begins at the current point in the source input stream.


    Field Summary
     boolean closeUnderlying
              If this is true, then a call to close() will close the underlying stream as well.
     
    Fields inherited from class ewe.io.StreamAdapter
    in, out, stream
     
    Fields inherited from class ewe.io.StreamObject
    napIterations, napTime, READWRITE_CLOSED, READWRITE_ERROR, READWRITE_WOULDBLOCK
     
    Fields inherited from class ewe.io.BasicStreamObject
    closed
     
    Fields inherited from class ewe.util.Errorable
    error
     
    Fields inherited from interface ewe.io.StreamCanPause
    PAUSE_UNTIL_CAN_READ, PAUSE_UNTIL_CAN_WRITE, PAUSE_UNTIL_CLOSED, PAUSE_UNTIL_FLUSHED
     
    Constructor Summary
    PartialInputStream(BasicStream input)
              Creates a new PartialInputStream with no limit.
    PartialInputStream(BasicStream input, int limit)
              Creates a new PartialInputStream with the specified limit.
    PartialInputStream(BasicStream input, long limit)
              Creates a new PartialInputStream with the specified limit.
    PartialInputStream(RandomAccessStream raf, int start, int limit)
               
    PartialInputStream(RandomAccessStream raf, long start, long limit)
               
     
    Method Summary
     boolean closeStream()
              This will not close the underlying stream unless closeUnderlying is true.
     boolean isOpen()
              Returns if the stream is open or not.
     int nonBlockingRead(byte[] buff, int offset, int count)
              This calls the nonBlockingRead() of the client BasicStream.
     int nonBlockingWrite(byte[] buff, int start, int length)
              This calls the nonBlockingWrite() of the client BasicStream.
     boolean pushback(byte[] bytes, int start, int count)
              Push back some bytes into the input stream.
     
    Methods inherited from class ewe.io.StreamAdapter
    flushStream, pauseUntilReady
     
    Methods inherited from class ewe.io.StreamObject
    close, doRead, doWrite, flush, nap, nap, read, readAByte, readBytes, readBytes, write, writeAByte, writeBytes, writeBytes
     
    Methods inherited from class ewe.io.BasicStreamObject
    getException, getName, read, read, throwIOException, toInputStream, toOutputStream, toStream, write, write
     
    Methods inherited from class ewe.util.Errorable
    returnError, returnError, returnError
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, toString
     
    Methods inherited from interface ewe.io.Stream
    flush, read, read, read, readBytes, readBytes, toInputStream, toOutputStream, write, write, write, writeBytes, writeBytes
     
    Methods inherited from interface ewe.io.BasicStream
    close
     

    Field Detail

    closeUnderlying

    public boolean closeUnderlying
    If this is true, then a call to close() will close the underlying stream as well.

    Constructor Detail

    PartialInputStream

    public PartialInputStream(BasicStream input)
    Creates a new PartialInputStream with no limit.


    PartialInputStream

    public PartialInputStream(BasicStream input,
                              int limit)
    Creates a new PartialInputStream with the specified limit. If the limit is -1, then there will be no limit imposed


    PartialInputStream

    public PartialInputStream(RandomAccessStream raf,
                              int start,
                              int limit)

    PartialInputStream

    public PartialInputStream(BasicStream input,
                              long limit)
    Creates a new PartialInputStream with the specified limit. If the limit is -1, then there will be no limit imposed


    PartialInputStream

    public PartialInputStream(RandomAccessStream raf,
                              long start,
                              long limit)
    Method Detail

    pushback

    public boolean pushback(byte[] bytes,
                            int start,
                            int count)
    Description copied from class: StreamAdapter
    Push back some bytes into the input stream. There is no limit on the number of bytes which can be pushed back. This can be called multiple times.

    Specified by:
    pushback in interface BufferedStream
    Overrides:
    pushback in class StreamAdapter

    nonBlockingWrite

    public int nonBlockingWrite(byte[] buff,
                                int start,
                                int length)
    Description copied from class: StreamAdapter
    This calls the nonBlockingWrite() of the client BasicStream.

    Specified by:
    nonBlockingWrite in interface BasicStream
    Overrides:
    nonBlockingWrite in class StreamAdapter

    nonBlockingRead

    public int nonBlockingRead(byte[] buff,
                               int offset,
                               int count)
    Description copied from class: StreamAdapter
    This calls the nonBlockingRead() of the client BasicStream.

    Specified by:
    nonBlockingRead in interface BasicStream
    Overrides:
    nonBlockingRead in class StreamAdapter

    closeStream

    public boolean closeStream()
                        throws IOException
    This will not close the underlying stream unless closeUnderlying is true.

    Specified by:
    closeStream in interface BasicStream
    Overrides:
    closeStream in class StreamAdapter
    Throws:
    IOException

    isOpen

    public boolean isOpen()
    Description copied from interface: BasicStream
    Returns if the stream is open or not.

    Specified by:
    isOpen in interface BasicStream
    Overrides:
    isOpen in class StreamAdapter