1:
2:
3:
10:
11: package ;
12:
13: import ;
14: import ;
15: import ;
16: import ;
17:
18: public class CoreInputStream extends InputStream
19: {
20:
21: protected RawData ptr;
22:
23:
24: protected int pos;
25:
26:
27: protected int mark;
28:
29:
30: protected int count;
31:
32: private native int unsafeGetByte (long offset);
33: private native int copyIntoByteArray (byte[] dest, int offset, int numBytes);
34:
35: public CoreInputStream (Core core)
36: {
37: ptr = core.ptr;
38: count = core.length;
39: }
40:
41: public synchronized int available()
42: {
43: return count - pos;
44: }
45:
46: public synchronized void mark(int readAheadLimit)
47: {
48:
49: mark = pos;
50: }
51:
52: public boolean markSupported()
53: {
54: return true;
55: }
56:
57: public synchronized int read()
58: {
59: if (pos < count)
60: return ((int) unsafeGetByte(pos++)) & 0xFF;
61: return -1;
62: }
63:
64: public synchronized int read(byte[] b, int off, int len)
65: {
66: if (pos >= count)
67: return -1;
68:
69: int numBytes = Math.min(count - pos, len);
70: copyIntoByteArray (b, off, numBytes);
71: pos += numBytes;
72: return numBytes;
73: }
74:
75: public synchronized void reset()
76: {
77: pos = mark;
78: }
79:
80: public synchronized long skip(long n)
81: {
82:
83:
84:
85:
86: long numBytes = Math.min ((long) (count - pos), n < 0 ? 0L : n);
87: pos += numBytes;
88: return numBytes;
89: }
90: }