ByteArrayInputStream

public class ByteArrayInputStream extends InputStream

A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream. An internal counter keeps track of the next byte to be supplied by the read method.

Closing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Field Summary

protected byte[] buf An array of bytes that was provided by the creator of the stream.
protected int count The index one greater than the last valid character in the input stream buffer.
protected int mark The currently marked position in the stream.
protected int pos The index of the next character to read from the input stream buffer.

Public Constructor Summary

ByteArrayInputStream(byte[] buf)
Creates a ByteArrayInputStream so that it uses buf as its buffer array.
ByteArrayInputStream(byte[] buf, int offset, int length)
Creates ByteArrayInputStream that uses buf as its buffer array.

Public Method Summary

synchronized int
available()
Returns the number of remaining bytes that can be read (or skipped over) from this input stream.
void
close()
Closing a ByteArrayInputStream has no effect.
void
mark(int readAheadLimit)
Set the current marked position in the stream.
boolean
markSupported()
Tests if this InputStream supports mark/reset.
synchronized int
read()
Reads the next byte of data from this input stream.
synchronized int
read(byte[] b, int off, int len)
Reads up to len bytes of data into an array of bytes from this input stream.
synchronized void
reset()
Resets the buffer to the marked position.
synchronized long
skip(long n)
Skips n bytes of input from this input stream.

Inherited Method Summary

Fields

protected byte[] buf

An array of bytes that was provided by the creator of the stream. Elements buf[0] through buf[count-1] are the only bytes that can ever be read from the stream; element buf[pos] is the next byte to be read.

protected int count

The index one greater than the last valid character in the input stream buffer. This value should always be nonnegative and not larger than the length of buf. It is one greater than the position of the last byte within buf that can ever be read from the input stream buffer.

protected int mark

The currently marked position in the stream. ByteArrayInputStream objects are marked at position zero by default when constructed. They may be marked at another position within the buffer by the mark() method. The current buffer position is set to this point by the reset() method.

If no mark has been set, then the value of mark is the offset passed to the constructor (or 0 if the offset was not supplied).