1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.util.cache;
17
18 import java.io.InputStream;
19
20
21
22
23 public class FastByteArrayInputStream extends InputStream {
24
25
26
27 protected byte[] buf = null;
28
29
30
31
32 protected int count = 0;
33
34
35
36
37 protected int pos = 0;
38
39 public FastByteArrayInputStream(byte[] buf, int count) {
40 this.buf = buf;
41 this.count = count;
42 }
43
44 public final int available() {
45 return count - pos;
46 }
47
48 public final int read() {
49 return (pos < count) ? (buf[pos++] & 0xff) : -1;
50 }
51
52 public final int read(byte[] b, int off, int len) {
53 if (pos >= count)
54 return -1;
55
56 if ((pos + len) > count)
57 len = (count - pos);
58
59 System.arraycopy(buf, pos, b, off, len);
60 pos += len;
61 return len;
62 }
63
64 public final long skip(long n) {
65 if ((pos + n) > count)
66 n = count - pos;
67 if (n < 0)
68 return 0;
69 pos += n;
70 return n;
71 }
72
73 }