刘光辉
117 分钟以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
    }
}