2007-09-26 17:27:09 +00:00
|
|
|
package java.io;
|
|
|
|
|
|
|
|
public class ByteArrayInputStream extends InputStream {
|
|
|
|
private final byte[] array;
|
|
|
|
private int position;
|
|
|
|
private final int length;
|
|
|
|
|
|
|
|
public ByteArrayInputStream(byte[] array, int offset, int length) {
|
|
|
|
this.array = array;
|
|
|
|
position = offset;
|
|
|
|
this.length = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int read() {
|
|
|
|
if (position < length) {
|
|
|
|
return array[position++] & 0xff;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-30 21:08:49 +00:00
|
|
|
public int read(byte[] buffer, int offset, int bufferLength) {
|
|
|
|
if (position < length) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (length-position < bufferLength) {
|
|
|
|
bufferLength = length-position;
|
|
|
|
}
|
|
|
|
System.arraycopy(buffer, offset, array, position, bufferLength);
|
|
|
|
position += bufferLength;
|
|
|
|
return bufferLength;
|
|
|
|
}
|
|
|
|
|
2007-09-26 17:27:09 +00:00
|
|
|
public int available() {
|
2007-09-26 17:45:44 +00:00
|
|
|
return length - position;
|
2007-09-26 17:27:09 +00:00
|
|
|
}
|
|
|
|
}
|