annotate src/treeVnc/InStream.java @ 6:01cdbc95142f default tip

update build.xml
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Mon, 30 Apr 2012 16:04:44 +0900
parents 756bfaf731f3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 package treeVnc;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 *
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 * This is free software; you can redistribute it and/or modify
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 * (at your option) any later version.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 *
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 * This software is distributed in the hope that it will be useful,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 * GNU General Public License for more details.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 *
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 * along with this software; if not, write to the Free Software
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 * USA.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 */
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 // rdr::InStream marshalls data from a buffer stored in RDR (RFB Data
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 // Representation).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 //
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 abstract public class InStream {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 // check() ensures there is buffer data for at least one item of size
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 // itemSize bytes. Returns the number of items in the buffer (up to a
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 // maximum of nItems).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 public final int check(int itemSize, int nItems) throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 if (ptr + itemSize * nItems > end) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 if (ptr + itemSize > end)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 return overrun(itemSize, nItems);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 nItems = (end - ptr) / itemSize;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 return nItems;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 public final void check(int itemSize) throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 if (ptr + itemSize > end)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 overrun(itemSize, 1);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 // readU/SN() methods read unsigned and signed N-bit integers.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 public final int readS8() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 check(1); return b[ptr++];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 public final int readS16() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 check(2); int b0 = b[ptr++];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 int b1 = b[ptr++] & 0xff; return b0 << 8 | b1;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 public final int readS32() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 check(4); int b0 = b[ptr++];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 int b1 = b[ptr++] & 0xff;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 int b2 = b[ptr++] & 0xff;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 int b3 = b[ptr++] & 0xff;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 return b0 << 24 | b1 << 16 | b2 << 8 | b3;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 public final int readU8() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 return readS8() & 0xff;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 public final int readU16() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 return readS16() & 0xffff;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 public final int readU32() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 return readS32() & 0xffffffff;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 // readString() reads a string - a U32 length followed by the data.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 public final String readString() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 int len = readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 if (len > maxStringLength)
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 throw new Exception("InStream max string length exceeded");
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 char[] str = new char[len];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 int i = 0;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 while (i < len) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 int j = i + check(1, len - i);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 while (i < j) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 str[i++] = (char)b[ptr++];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 return new String(str);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 // maxStringLength protects against allocating a huge buffer. Set it
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 // higher if you need longer strings.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 public static int maxStringLength = 65535;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 public final void skip(int bytes) throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 while (bytes > 0) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 int n = check(1, bytes);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 ptr += n;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 bytes -= n;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 // readBytes() reads an exact number of bytes into an array at an offset.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 public void readBytes(byte[] data, int offset, int length) throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 int offsetEnd = offset + length;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 while (offset < offsetEnd) {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 int n = check(1, offsetEnd - offset);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 System.arraycopy(b, ptr, data, offset, n);
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 ptr += n;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 offset += n;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 // readOpaqueN() reads a quantity "without byte-swapping". Because java has
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 // no byte-ordering, we just use big-endian.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 public final int readOpaque8() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 return readU8();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 public final int readOpaque16() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 return readU16();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 public final int readOpaque32() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 return readU32();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 public final int readOpaque24A() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 check(3); int b0 = b[ptr++];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 int b1 = b[ptr++]; int b2 = b[ptr++];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 return b0 << 24 | b1 << 16 | b2 << 8;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 public final int readOpaque24B() throws Exception {
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 check(3); int b0 = b[ptr++];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 int b1 = b[ptr++]; int b2 = b[ptr++];
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 return b0 << 16 | b1 << 8 | b2;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 // pos() returns the position in the stream.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 abstract public int pos();
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 // bytesAvailable() returns true if at least one byte can be read from the
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 // stream without blocking. i.e. if false is returned then readU8() would
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 // block.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 public boolean bytesAvailable() { return end != ptr; }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 // getbuf(), getptr(), getend() and setptr() are "dirty" methods which allow
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 // you to manipulate the buffer directly. This is useful for a stream which
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 // is a wrapper around an underlying stream.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 public final byte[] getbuf() { return b; }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 public final int getptr() { return ptr; }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 public final int getend() { return end; }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 public final void setptr(int p) { ptr = p; }
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 // overrun() is implemented by a derived class to cope with buffer overrun.
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 // It ensures there are at least itemSize bytes of buffer data. Returns
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 // the number of items in the buffer (up to a maximum of nItems). itemSize
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 // is supposed to be "small" (a few bytes).
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 abstract protected int overrun(int itemSize, int nItems) throws Exception;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 protected InStream() {}
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 protected byte[] b;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 protected int ptr;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 protected int end;
756bfaf731f3 create new repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 }