FastInputStream.java [plain text]
package com.sleepycat.bdb.util;
import java.io.IOException;
import java.io.InputStream;
public class FastInputStream extends InputStream {
protected int len;
protected int off;
protected int mark;
protected byte[] buf;
public FastInputStream(byte[] buffer) {
buf = buffer;
len = buffer.length;
}
public FastInputStream(byte[] buffer, int offset, int length) {
buf = buffer;
off = offset;
len = length;
}
public int available() {
return len - off;
}
public boolean markSupported() {
return true;
}
public void mark(int pos) {
mark = pos;
}
public void reset() {
off = mark;
}
public long skip(long count) {
int myCount = (int) count;
if (myCount + off > len) {
myCount = len - off;
}
off += myCount;
return myCount;
}
public int read() throws IOException {
return (off < len) ? (buf[off++] & 0xff) : (-1);
}
public int read(byte[] toBuf) throws IOException {
return read(toBuf, 0, toBuf.length);
}
public int read(byte[] toBuf, int offset, int length) throws IOException {
int avail = len - off;
if (avail <= 0) {
return -1;
}
if (length > avail) {
length = avail;
}
for (int i = 0; i < length; i++) {
toBuf[offset++] = buf[off++];
}
return length;
}
public byte[] getBufferBytes() {
return buf;
}
public int getBufferOffset() {
return off;
}
public int getBufferLength() {
return len;
}
}