java.io.ByteArrayInputStream
java.io.InputStream
None
None
JDK 1.0 or later
A ByteArrayInputStream is a stream whose data comes from a byte array. None of the methods of this class throw an IOException because the data comes from an array instead of an actual I/O device. This class does not support the ability to mark a position in the stream. A call to reset(), however, does position the stream at the beginning of the byte array.
The position of the end of the stream depends on the constructor used. If the ByteArrayInputStream(byte[] buf) constructor is used, the end of the stream is the end of the byte array. If the ByteArrayInputStream(byte[] buf, int offset, int length) constructor is used, the end of the stream is reached at the index given by offset+length.
public class java.io.ByteArrayInputStream extends java.io.InputStream { // Variables protected byte[] buf; protected int count; protected int pos; // Constructors public ByteArrayInputStream(byte[] buf); public ByteArrayInputStream(byte[] buf, int offset, int length); // Instance Methods public synchronized int available(); public synchronized int read(); public synchronized int read(byte[] b, int off, int len); public synchronized void reset(); public synchronized long skip(long n); }
The buffer represented by this stream.
A placeholder that marks the end of the data this ByteArrayInputStream represents.
The current position in the buffer.
The stream source.
This constructor creates a ByteArrayInputStream object that uses the given array of bytes as its data source. The data is not copied, so changes made to the array affect the data the ByteArrayInputStream returns.
The stream source.
An index into the buffer where the stream should begin.
The number of bytes to read.
This constructor creates a ByteArrayInputStream that uses, as its data source, length bytes in a given array of bytes, starting at offset bytes from the beginning of the array. The data is not copied, so changes made to the array affect the data the ByteArrayInputStream returns.
The number of bytes remaining to be read in the array.
InputStream.available()
This method returns the number of bytes remaining to be read in the byte array.
The next byte or -1 if the end of the stream is encountered.
InputStream.read()
This method returns the next byte in the array.
An array to read bytes into.
An offset into b.
The number of bytes to read.
The number of bytes read or -1 if the end of the stream is encountered.
InputStream.read(byte[], int, int)
This method copies up to len bytes from its internal byte array into the given array b, starting at index off.
InputStream.reset()
This method resets the position of the input stream to the beginning of the byte array. If you specified an offset into the array, you might expect this method to reset the position to where you first started reading from the stream, but that is not the case.
The number of bytes to skip.
The number of bytes skipped.
InputStream.skip()
This method skips n bytes of input. If you try to skip past the end of the array, the stream is positioned at the end of the array.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
close() |
InputStream |
equals (Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
mark(int) |
InputStream |
markSupported () |
InputStream |
notify() |
Object |
notifyAll() |
Object |
read(byte[]) |
InputStream |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
InputStream, String