package jnpf.fileStorage.dms;
|
|
import javax.imageio.stream.ImageInputStreamImpl;
|
import java.io.IOException;
|
import java.util.Objects;
|
|
/** Seekable ImageIO input backed directly by the already-buffered source bytes. */
|
final class DmsByteArrayImageInputStream extends ImageInputStreamImpl {
|
private final byte[] source;
|
|
DmsByteArrayImageInputStream(byte[] source) {
|
this.source = Objects.requireNonNull(source, "source");
|
}
|
|
@Override
|
public int read() throws IOException {
|
checkClosed();
|
bitOffset = 0;
|
if (streamPos >= source.length) {
|
return -1;
|
}
|
return source[(int) streamPos++] & 0xFF;
|
}
|
|
@Override
|
public int read(byte[] target, int offset, int length) throws IOException {
|
checkClosed();
|
Objects.checkFromIndexSize(offset, length, target.length);
|
bitOffset = 0;
|
if (length == 0) {
|
return 0;
|
}
|
if (streamPos >= source.length) {
|
return -1;
|
}
|
int count = (int) Math.min(length, source.length - streamPos);
|
System.arraycopy(source, (int) streamPos, target, offset, count);
|
streamPos += count;
|
return count;
|
}
|
|
@Override
|
public long length() {
|
return source.length;
|
}
|
}
|