ByteArrayInputStream

A <code>ByteArrayInputStream</code> 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 <code>read</code> method. <p> Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in this class can be called after the stream has been closed without generating an <tt>IOException</tt>.

Constructors

this
this(byte[] buf)

Creates a <code>ByteArrayInputStream</code> so that it uses <code>buf</code> as its buffer array. The buffer array is not copied. The initial value of <code>pos</code> is <code>0</code> and the initial value of <code>count</code> is the length of <code>buf</code>.

this
this(byte[] buf, int offset, size_t length)

Creates <code>ByteArrayInputStream</code> that uses <code>buf</code> as its buffer array. The initial value of <code>pos</code> is <code>offset</code> and the initial value of <code>count</code> is the minimum of <code>offset+length</code> and <code>buf.length</code>. The buffer array is not copied. The buffer's mark is set to the specified offset.

Members

Aliases

read
alias read = InputStream.read
Undocumented in source.

Functions

available
int available()

Returns the number of remaining bytes that can be read (or skipped over) from this input stream. <p> The value returned is <code>count&nbsp;- pos</code>, which is the number of bytes remaining to be read from the input buffer.

getRawBuffer
byte[] getRawBuffer()
Undocumented in source. Be warned that the author may not have intended to support it.
mark
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. <p> 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).

markSupported
bool markSupported()

Tests if this <code>InputStream</code> supports mark/reset. The <code>markSupported</code> method of <code>ByteArrayInputStream</code> always returns <code>true</code>.

position
void position(int index)
Undocumented in source. Be warned that the author may not have intended to support it.
read
int read()

Reads the next byte of data from this input stream. The value byte is returned as an <code>int</code> in the range <code>0</code> to <code>255</code>. If no byte is available because the end of the stream has been reached, the value <code>-1</code> is returned. <p> This <code>read</code> method cannot block.

read
int read(byte[] b, int off, int len)

Reads up to <code>len</code> bytes of data into an array of bytes from this input stream. If <code>pos</code> equals <code>count</code>, then <code>-1</code> is returned to indicate end of file. Otherwise, the number <code>k</code> of bytes read is equal to the smaller of <code>len</code> and <code>count-pos</code>. If <code>k</code> is positive, then bytes <code>bufpos</code> through <code>buf[pos+k-1]</code> are copied into <code>boff</code> through <code>b[off+k-1]</code> in the manner performed by <code>System.arraycopy</code>. The value <code>k</code> is added into <code>pos</code> and <code>k</code> is returned. <p> This <code>read</code> method cannot block.

reset
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.

skip
long skip(long n)

Skips <code>n</code> bytes of input from this input stream. Fewer bytes might be skipped if the end of the input stream is reached. The actual number <code>k</code> of bytes to be skipped is equal to the smaller of <code>n</code> and <code>count-pos</code>. The value <code>k</code> is added into <code>pos</code> and <code>k</code> is returned.

Variables

_mark
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 <code>mark()</code> method. The current buffer position is set to this point by the <code>reset()</code> method. <p> 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).

buf
byte[] buf;

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

count
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 <code>buf</code>. It is one greater than the position of the last byte within <code>buf</code> that can ever be read from the input stream buffer.

pos
int pos;

The index of the next character to read from the input stream buffer. This value should always be nonnegative and not larger than the value of <code>count</code>. The next byte to be read from the input stream buffer will be <code>bufpos</code>.

Inherited Members

From InputStream

read
int read()

Reads the next byte of data from the input stream. The value byte is returned as an <code>int</code> in the range <code>0</code> to <code>255</code>. If no byte is available because the end of the stream has been reached, the value <code>-1</code> is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

read
int read(byte[] b)

Reads some number of bytes from the input stream and stores them into the buffer array <code>b</code>. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

read
int read(byte[] b, int off, int len)

Reads up to <code>len</code> bytes of data from the input stream into an array of bytes. An attempt is made to read as many as <code>len</code> bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

skip
long skip(long n)

Skips over and discards <code>n</code> bytes of data from this input stream. The <code>skip</code> method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly <code>0</code>. This may result from any of a number of conditions; reaching end of file before <code>n</code> bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If {@code n} is negative, the {@code skip} method for class {@code InputStream} always returns 0, and no bytes are skipped. Subclasses may handle the negative value differently.

available
int available()

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

close
void close()

Closes this input stream and releases any system resources associated with the stream.

mark
void mark(int readlimit)

Marks the current position in this input stream. A subsequent call to the <code>reset</code> method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

reset
void reset()

Repositions this stream to the position at the time the <code>mark</code> method was last called on this input stream.

position
void position(int index)

set a new position

markSupported
bool markSupported()

Tests if this input stream supports the <code>mark</code> and <code>reset</code> methods. Whether or not <code>mark</code> and <code>reset</code> are supported is an invariant property of a particular input stream instance. The <code>markSupported</code> method of <code>InputStream</code> returns <code>false</code>.

Meta