1
2 package org.galagosearch.tupleflow;
3
4 import java.io.DataInput;
5 import java.io.IOException;
6
7 /***
8 *
9 * @author trevor
10 */
11 public class ArrayInput {
12 private DataInput input;
13
14 public ArrayInput(DataInput i) {
15 input = i;
16 }
17
18 public int readInt() throws IOException {
19 return input.readInt();
20 }
21
22 public int[] readInts() throws IOException {
23 int count = readInt();
24 int[] result = new int[count];
25
26 for (int i = 0; i < count; i++) {
27 result[i] = readInt();
28 }
29
30 return result;
31 }
32
33 public long readLong() throws IOException {
34 return input.readLong();
35 }
36
37 public long[] readLongs() throws IOException {
38 int count = readInt();
39 long[] result = new long[count];
40
41 for (int i = 0; i < count; i++) {
42 result[i] = readLong();
43 }
44
45 return result;
46 }
47
48 public char readChar() throws IOException {
49 return input.readChar();
50 }
51
52 public char[] readChars() throws IOException {
53 int count = readInt();
54 char[] result = new char[count];
55
56 for (int i = 0; i < count; i++) {
57 result[i] = readChar();
58 }
59
60 return result;
61 }
62
63 public boolean readBoolean() throws IOException {
64 return input.readByte() != 0 ? true : false;
65 }
66
67 public byte readByte() throws IOException {
68 return input.readByte();
69 }
70
71 public byte[] readBytes() throws IOException {
72 int count = readInt();
73 byte[] result = new byte[count];
74 input.readFully(result);
75 return result;
76 }
77
78 public short readShort() throws IOException {
79 return input.readShort();
80 }
81
82 public short[] readShorts() throws IOException {
83 int count = readInt();
84 short[] result = new short[count];
85
86 for (int i = 0; i < count; i++) {
87 result[i] = readShort();
88 }
89
90 return result;
91 }
92
93 public double readDouble() throws IOException {
94 return input.readDouble();
95 }
96
97 public double[] readDoubles() throws IOException {
98 int count = readInt();
99 double[] result = new double[count];
100
101 for (int i = 0; i < count; i++) {
102 result[i] = readDouble();
103 }
104
105 return result;
106 }
107
108 public float readFloat() throws IOException {
109 return input.readFloat();
110 }
111
112 public float[] readFloats() throws IOException {
113 int count = readInt();
114 float[] result = new float[count];
115
116 for (int i = 0; i < count; i++) {
117 result[i] = readFloat();
118 }
119
120 return result;
121 }
122
123 public String readString() throws IOException {
124 byte[] bytes = readBytes();
125 char[] chars = new char[bytes.length];
126
127 for (int i = 0; i < bytes.length; i++) {
128 if (bytes[i] < 0) {
129 return new String(bytes, "UTF-8");
130 }
131 chars[i] = (char) bytes[i];
132 }
133
134 return new String(chars);
135 }
136
137 public String[] readStrings() throws IOException {
138 int count = readInt();
139 String[] result = new String[count];
140 for (int i = 0; i < count; i++) {
141 result[i] = readString();
142 }
143 return result;
144 }
145
146 public DataInput getDataInput() {
147 return input;
148 }
149 }
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224