Methods Summary |
---|
public synchronized int | available()Returns the number of bytes that are available before this stream will
block. This method returns the number of bytes yet to be read from the
source byte array.
return count - pos;
|
public void | close()Closes this stream and frees resources associated with this stream.
// Do nothing on close, this matches JDK behaviour.
|
public synchronized void | mark(int readlimit)Sets a mark position in this ByteArrayInputStream. The parameter
{@code readlimit} is ignored. Sending {@code reset()} will reposition the
stream back to the marked position.
mark = pos;
|
public boolean | markSupported()Indicates whether this stream supports the {@code mark()} and
{@code reset()} methods. Returns {@code true} since this class supports
these methods.
return true;
|
public synchronized int | read()Reads a single byte from the source byte array and returns it as an
integer in the range from 0 to 255. Returns -1 if the end of the source
array has been reached.
return pos < count ? buf[pos++] & 0xFF : -1;
|
public synchronized int | read(byte[] b, int offset, int length)Reads at most {@code len} bytes from this stream and stores
them in byte array {@code b} starting at {@code offset}. This
implementation reads bytes from the source byte array.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
// BEGIN android-changed
if (b == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
// avoid int overflow
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// removed redundant check, used (offset | length) < 0 instead of
// (offset < 0) || (length < 0) to safe one operation
if ((offset | length) < 0 || length > b.length - offset) {
throw new IndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
// Are there any bytes available?
if (this.pos >= this.count) {
return -1;
}
if (length == 0) {
return 0;
}
int copylen = this.count - pos < length ? this.count - pos : length;
System.arraycopy(buf, pos, b, offset, copylen);
pos += copylen;
return copylen;
|
public synchronized void | reset()Resets this stream 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 has been provided.
pos = mark;
|
public synchronized long | skip(long n)Skips {@code count} number of bytes in this InputStream. Subsequent
{@code read()}s will not return these bytes unless {@code reset()} is
used. This implementation skips {@code count} number of bytes in the
target stream. It does nothing and returns 0 if {@code n} is negative.
if (n <= 0) {
return 0;
}
int temp = pos;
pos = this.count - pos < n ? this.count : (int) (pos + n);
return pos - temp;
|