corda/classpath/java/io/ByteArrayInputStream.java

39 lines
856 B
Java
Raw Normal View History

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;
}
}
public int read(byte[] buffer, int offset, int bufferLength) {
if (position < length) {
return -1;
}
int remaining = length-position;
if (remaining < bufferLength) {
bufferLength = remaining;
}
2007-10-30 21:10:32 +00:00
System.arraycopy(array, position, buffer, offset, 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
}
}