Class: java.io.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.
Inheritance
Superclass tree:- java.lang.Object
- java.io.InputStream
- java.io.ByteArrayInputStream
Methods
-
ByteArrayInputStreamtop
public ByteArrayInputStream(byte[] buf)Creates aByteArrayInputStreamso that it usesbufas its buffer array. The buffer array is not copied. The initial value ofposis0and the initial value ofcountis the length ofbuf. -
ByteArrayInputStreamtop
public ByteArrayInputStream(byte[] buf, int offset, int length)CreatesByteArrayInputStreamthat usesbufas its buffer array. The initial value ofposisoffsetand the initial value ofcountis the minimum ofoffset+lengthandbuf.length. The buffer array is not copied. The buffer's mark is set to the specified offset. -
availabletop
public synchronized int available()Returns the number of remaining bytes that can be read (or skipped over) from this input stream.The value returned is
count - pos, which is the number of bytes remaining to be read from the input buffer.- Override hierarchy:
- available from InputStream
-
closetop
public void close() throws IOExceptionClosing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.- Override hierarchy:
- close from InputStream
-
marktop
public void mark(int readAheadLimit)Set the current 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 this method.If no mark has been set, then the value of the mark is the offset passed to the constructor (or 0 if the offset was not supplied).
Note: The
readAheadLimitfor this class has no meaning.- Override hierarchy:
- mark from InputStream
-
markSupportedtop
public boolean markSupported()Tests if thisInputStreamsupports mark/reset. ThemarkSupportedmethod ofByteArrayInputStreamalways returnstrue.- Override hierarchy:
- markSupported from InputStream
-
readtop
public synchronized int read()Reads the next byte of data from this input stream. The value byte is returned as anintin the range0to255. If no byte is available because the end of the stream has been reached, the value-1is returned.This
readmethod cannot block.- Override hierarchy:
- read from InputStream
-
readtop
public synchronized int read(byte[] b, int off, int len)Reads up tolenbytes of data into an array of bytes from this input stream. Ifposequalscount, then-1is returned to indicate end of file. Otherwise, the numberkof bytes read is equal to the smaller oflenandcount-pos. Ifkis positive, then bytesbuf[pos]throughbuf[pos+k-1]are copied intob[off]throughb[off+k-1]in the manner performed bySystem.arraycopy. The valuekis added intoposandkis returned.This
readmethod cannot block.- Override hierarchy:
- read from InputStream
-
resettop
public synchronized void reset()Resets the buffer to the marked position. The marked position is 0 unless another position was marked or an offset was specified in the constructor.- Override hierarchy:
- reset from InputStream
-
skiptop
public synchronized long skip(long n)Skipsnbytes of input from this input stream. Fewer bytes might be skipped if the end of the input stream is reached. The actual numberkof bytes to be skipped is equal to the smaller ofnandcount-pos. The valuekis added intoposandkis returned.- Override hierarchy:
- skip from InputStream
Fields
-
buf
protected byte[] bufAn array of bytes that was provided by the creator of the stream. Elementsbuf[0]throughbuf[count-1]are the only bytes that can ever be read from the stream; elementbuf[pos]is the next byte to be read. -
count
protected int countThe 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 ofbuf. It is one greater than the position of the last byte withinbufthat can ever be read from the input stream buffer. -
mark
protected int markThe 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 themark()method. The current buffer position is set to this point by thereset()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).
-
pos
protected int posThe index of the next character to read from the input stream buffer. This value should always be nonnegative and not larger than the value ofcount. The next byte to be read from the input stream buffer will bebuf[pos].
