org.norther.tammi.acorn.io
Class CollectorInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.norther.tammi.acorn.io.CollectorInputStream
All Implemented Interfaces:
Closeable

public class CollectorInputStream
extends InputStream

An input stream wrapper collecting read input into its internal buffer.

Author:
Ilkka Priha

Constructor Summary
CollectorInputStream(InputStream in)
          Constructs a new collector input stream.
 
Method Summary
 int available()
          Returns the number of bytes available.
 void close()
          Closes the stream.
 int getByteCount()
          Gets the number of collected bytes.
 byte[] getBytes()
          Gets the byte buffer.
 void mark(int readlimit)
          Marks the current position.
 boolean markSupported()
          Checks whether mark is supported.
 int read()
          Reads the next byte.
 int read(byte[] bb)
          Reads some number of bytes.
 int read(byte[] bb, int off, int len)
          Reads the specified number of bytes into a buffer.
 void reset()
          Resets the stream.
 void reset(InputStream in)
          Resets the collector for a new stream.
 long skip(long n)
          Skips the given number of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectorInputStream

public CollectorInputStream(InputStream in)
Constructs a new collector input stream.

Parameters:
in - an input stream.
Method Detail

available

public int available()
              throws IOException
Returns the number of bytes available.

Overrides:
available in class InputStream
Returns:
the number of bytes.
Throws:
IOException - on I/O errors.

read

public int read()
         throws IOException
Reads the next byte.

Specified by:
read in class InputStream
Returns:
the byte.
Throws:
IOException - for I/O errors.

read

public int read(byte[] bb)
         throws IOException
Reads some number of bytes.

Overrides:
read in class InputStream
Parameters:
bb - a buffer.
Returns:
the number of bytes read.
Throws:
IOException - on error.

read

public int read(byte[] bb,
                int off,
                int len)
         throws IOException
Reads the specified number of bytes into a buffer.

Overrides:
read in class InputStream
Parameters:
bb - a buffer.
off - an offset.
len - the number of bytes to read.
Returns:
the number of bytes read.
Throws:
IOException - for I/O errors.

mark

public void mark(int readlimit)
Marks the current position.

Overrides:
mark in class InputStream
Parameters:
readlimit - an invalidation limit.

markSupported

public boolean markSupported()
Checks whether mark is supported.

Overrides:
markSupported in class InputStream
Returns:
true or false.

reset

public void reset()
           throws IOException
Resets the stream.

Overrides:
reset in class InputStream
Throws:
IOException - for I/O errors.

skip

public long skip(long n)
          throws IOException
Skips the given number of bytes.

Overrides:
skip in class InputStream
Parameters:
n - the number of bytes to skip.
Returns:
the number of bytes skipped.
Throws:
IOException - for I/O errors.

close

public void close()
           throws IOException
Closes the stream.

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException - for I/O errors.

reset

public void reset(InputStream in)
Resets the collector for a new stream.

Parameters:
in - a new input stream.

getByteCount

public int getByteCount()
Gets the number of collected bytes.

Returns:
the number of collected bytes.

getBytes

public byte[] getBytes()
Gets the byte buffer.

Returns:
the byte buffer.


Copyright © 2004 The Norther Organization. All rights reserved.