java.io
Class ByteArrayInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.ByteArrayInputStream

public class ByteArrayInputStream
extends InputStream

This class implements a buffer that can be used as an InputStream.


Field Summary
protected  byte[] buf
          The buffer where data is stored.
protected  int count
          The number of characters to use in the buffer.
protected  int pos
          The current position in the buffer.
 
Constructor Summary
ByteArrayInputStream(byte[] buf)
          Creates an ByteArrayInputStream from the specified array of bytes.
ByteArrayInputStream(byte[] buf, int offset, int length)
          Creates an ByteArrayInputStream from the specified array of bytes.
 
Method Summary
 int available()
          Returns the number of available bytes in the buffer.
 int read()
          Reads a byte of data.
 int read(byte[] b, int off, int len)
          Reads into an array of bytes.
 void reset()
          Resets the buffer to the beginning.
 long skip(long n)
          Skips n bytes of input.
 
Methods inherited from class java.io.InputStream
close, mark, markSupported, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

protected byte[] buf
The buffer where data is stored.


pos

protected int pos
The current position in the buffer.


count

protected int count
The number of characters to use in the buffer.

Constructor Detail

ByteArrayInputStream

public ByteArrayInputStream(byte[] buf)
Creates an ByteArrayInputStream from the specified array of bytes.

Parameters:
buf - the input buffer (not copied)

ByteArrayInputStream

public ByteArrayInputStream(byte[] buf,
                            int offset,
                            int length)
Creates an ByteArrayInputStream from the specified array of bytes.

Parameters:
buf - the input buffer (not copied)
offset - the offset of the first byte to read
length - the number of bytes to read
Method Detail

read

public int read()
Reads a byte of data.

Specified by:
read in class InputStream
Returns:
the byte read, or -1 if the end of the stream is reached.

read

public int read(byte[] b,
                int off,
                int len)
Reads into an array of bytes.

Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the actual number of bytes read; -1 is returned when the end of the stream is reached.

skip

public long skip(long n)
Skips n bytes of input.

Overrides:
skip in class InputStream
Parameters:
n - the number of bytes to be skipped
Returns:
the actual number of bytes skipped.

available

public int available()
Returns the number of available bytes in the buffer.

Overrides:
available in class InputStream
Returns:
the number of available bytes.

reset

public void reset()
Resets the buffer to the beginning.

Overrides:
reset in class InputStream