Build 1.0_r1(from source)

java.io
Class ByteArrayInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.ByteArrayInputStream
All Implemented Interfaces:
Closeable

public class ByteArrayInputStream
extends InputStream

ByteArrayInputStream is used for streaming over a byte array.

See Also:
ByteArrayOutputStream

Field Summary
protected  byte[] buf
          The byte array containing the bytes to stream over.
protected  int count
          The total number of bytes initially available in the byte array buf.
protected  int mark
          The current mark position.
protected  int pos
          The current position within the byte array.
 
Constructor Summary
ByteArrayInputStream(byte[] buf)
          Constructs a new ByteArrayInputStream on the byte array buf.
ByteArrayInputStream(byte[] buf, int offset, int length)
          Constructs a new ByteArrayInputStream on the byte array buf with the position set to offset and the number of bytes available set to offset + length.
 
Method Summary
 int available()
          Returns a int representing then number of bytes that are available before this ByteArrayInputStream will block.
 void close()
          Close the ByteArrayInputStream.
 void mark(int readlimit)
          Set a Mark position in this ByteArrayInputStream.
 boolean markSupported()
          Returns a boolean indicating whether or not this ByteArrayInputStream supports mark() and reset().
 int read()
          Reads a single byte from this ByteArrayInputStream and returns the result as an int.
 int read(byte[] b, int offset, int length)
          Reads at most len bytes from this ByteArrayInputStream and stores them in byte array b starting at offset off.
 void reset()
          Reset this ByteArrayInputStream to the last marked location.
 long skip(long n)
          Skips count number of bytes in this InputStream.
 
Methods inherited from class java.io.InputStream
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 byte array containing the bytes to stream over.


pos

protected int pos
The current position within the byte array.


mark

protected int mark
The current mark position. Initially set to 0 or the offset parameter within the constructor.


count

protected int count
The total number of bytes initially available in the byte array buf.

Constructor Detail

ByteArrayInputStream

public ByteArrayInputStream(byte[] buf)
Constructs a new ByteArrayInputStream on the byte array buf.

Parameters:
buf - the byte array to stream over

ByteArrayInputStream

public ByteArrayInputStream(byte[] buf,
                            int offset,
                            int length)
Constructs a new ByteArrayInputStream on the byte array buf with the position set to offset and the number of bytes available set to offset + length.

Parameters:
buf - the byte array to stream over
offset - the offset in buf to start streaming at
length - the number of bytes available to stream over.
Method Detail

available

public int available()
Returns a int representing then number of bytes that are available before this ByteArrayInputStream will block. This method returns the number of bytes yet to be read from the underlying byte array.

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

close

public void close()
           throws IOException
Close the ByteArrayInputStream. This implementation frees up resources associated with this stream.

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

mark

public void mark(int readlimit)
Set a Mark position in this ByteArrayInputStream. The parameter readLimit is ignored. Sending reset() will reposition the stream back to the marked position.

Overrides:
mark in class InputStream
Parameters:
readlimit - ignored.

markSupported

public boolean markSupported()
Returns a boolean indicating whether or not this ByteArrayInputStream supports mark() and reset(). This implementation returns true.

Overrides:
markSupported in class InputStream
Returns:
true indicates this stream supports mark/reset, false otherwise.

read

public int read()
Reads a single byte from this ByteArrayInputStream and returns the result as an int. The low-order byte is returned or -1 of the end of stream was encountered. This implementation returns the next available byte from the target byte array.

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

read

public int read(byte[] b,
                int offset,
                int length)
Reads at most len bytes from this ByteArrayInputStream and stores them in byte array b starting at offset off. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered. This implementation reads bytes from the target byte array.

Overrides:
read in class InputStream
Parameters:
b - the byte array in which to store the read bytes.
offset - the offset in b to store the read bytes.
length - the maximum number of bytes to store in b.
Returns:
the number of bytes actually read or -1 if end of stream.

reset

public void reset()
Reset this ByteArrayInputStream to the last marked location. This implementation resets the position to either the marked position, the start position supplied in the constructor or 0 if neither is provided.

Overrides:
reset in class InputStream

skip

public long skip(long n)
Skips count number of bytes in this InputStream. Subsequent read()'s will not return these bytes unless reset() is used. This implementation skips count number of bytes in the target stream.

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

Build 1.0_r1(from source)

Please submit a feedback, bug or feature