/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. * */ package com.sleepycat.util; import java.io.InputStream; /** * A replacement for ByteArrayInputStream that does not synchronize every * byte read. * *
This class extends {@link InputStream} and its read()
* methods allow it to be used as a standard input stream. In addition, it
* provides readFast()
methods that are not declared to throw
* IOException
. IOException
is never thrown by this
* class.
skip() but takes an int parameter instead of a
* long, and does not check whether the count given is larger than the
* number of remaining bytes.
* @see #skip(long)
*/
public final void skipFast(int count) {
off += count;
}
/**
* Equivalent to read() but does not throw
* IOException
.
* @see #read()
*/
public final int readFast() {
return (off < len) ? (buf[off++] & 0xff) : (-1);
}
/**
* Equivalent to read(byte[]) but does not throw
* IOException
.
* @see #read(byte[])
*/
public final int readFast(byte[] toBuf) {
return readFast(toBuf, 0, toBuf.length);
}
/**
* Equivalent to read(byte[],int,int) but does not throw
* IOException
.
* @see #read(byte[],int,int)
*/
public final int readFast(byte[] toBuf, int offset, int length) {
int avail = len - off;
if (avail <= 0) {
return -1;
}
if (length > avail) {
length = avail;
}
System.arraycopy(buf, off, toBuf, offset, length);
off += length;
return length;
}
/**
* Returns the underlying data being read.
*
* @return the underlying data.
*/
public final byte[] getBufferBytes() {
return buf;
}
/**
* Returns the offset at which data is being read from the buffer.
*
* @return the offset at which data is being read.
*/
public final int getBufferOffset() {
return off;
}
/**
* Returns the end of the buffer being read.
*
* @return the end of the buffer.
*/
public final int getBufferLength() {
return len;
}
}