Debian Codegraph @

src/main/java/io/airlift/slice/SliceInput.java

raw
1 /*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14 package io.airlift.slice;
15
16 import java.io.DataInput;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.io.OutputStream;
20
21 @SuppressWarnings("JavaDoc") // IDEA-81310
22 public abstract class SliceInput
23 extends InputStream
24 implements DataInput
25 {
26 /**
27 * Returns the {@code position} of this buffer.
28 */
29 public abstract long position();
30
31 /**
32 * Sets the {@code position} of this buffer.
33 *
34 * @throws IndexOutOfBoundsException if the specified {@code position} is
35 * less than {@code 0} or
36 * greater than {@code this.writerIndex}
37 */
38 public abstract void setPosition(long position);
39
40 /**
41 * Returns {@code true}
42 * if and only if {@code available()} is greater
43 * than {@code 0}.
44 */
45 public abstract boolean isReadable();
46
47 /**
48 * Returns the number of bytes that can be read without blocking.
49 */
50 @SuppressWarnings("AbstractMethodOverridesConcreteMethod")
51 @Override
52 public abstract int available();
53
54 @Override
55 public abstract int read();
56
57 /**
58 * Returns true if the byte at the current {@code position} is not {@code 0} and increases
59 * the {@code position} by {@code 1} in this buffer.
60 *
61 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 1}
62 */
63 @Override
64 public abstract boolean readBoolean();
65
66 /**
67 * Gets a byte at the current {@code position} and increases
68 * the {@code position} by {@code 1} in this buffer.
69 *
70 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 1}
71 */
72 @Override
73 public abstract byte readByte();
74
75 /**
76 * Gets an unsigned byte at the current {@code position} and increases
77 * the {@code position} by {@code 1} in this buffer.
78 *
79 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 1}
80 */
81 @Override
82 public abstract int readUnsignedByte();
83
84 /**
85 * Gets a 16-bit short integer at the current {@code position}
86 * and increases the {@code position} by {@code 2} in this buffer.
87 *
88 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 2}
89 */
90 @Override
91 public abstract short readShort();
92
93 /**
94 * Gets an unsigned 16-bit short integer at the current {@code position}
95 * and increases the {@code position} by {@code 2} in this buffer.
96 *
97 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 2}
98 */
99 @Override
100 public abstract int readUnsignedShort();
101
102 /**
103 * Gets a 32-bit integer at the current {@code position}
104 * and increases the {@code position} by {@code 4} in this buffer.
105 *
106 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 4}
107 */
108 @Override
109 public abstract int readInt();
110
111 /**
112 * Gets an unsigned 32-bit integer at the current {@code position}
113 * and increases the {@code position} by {@code 4} in this buffer.
114 *
115 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 4}
116 */
117 public final long readUnsignedInt()
118 {
119 return readInt() & 0xFFFFFFFFL;
120 }
121
122 /**
123 * Gets a 64-bit long at the current {@code position}
124 * and increases the {@code position} by {@code 8} in this buffer.
125 *
126 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 8}
127 */
128 @Override
129 public abstract long readLong();
130
131 /**
132 * Gets a 32-bit float at the current {@code position}
133 * and increases the {@code position} by {@code 4} in this buffer.
134 *
135 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 4}
136 */
137 @Override
138 public abstract float readFloat();
139
140 /**
141 * Gets a 64-bit double at the current {@code position}
142 * and increases the {@code position} by {@code 8} in this buffer.
143 *
144 * @throws IndexOutOfBoundsException if {@code this.available()} is less than {@code 8}
145 */
146 @Override
147 public abstract double readDouble();
148
149 /**
150 * Returns a new slice of this buffer's sub-region starting at the current
151 * {@code position} and increases the {@code position} by the size
152 * of the new slice (= {@code length}).
153 *
154 * @param length the size of the new slice
155 * @return the newly created slice
156 * @throws IndexOutOfBoundsException if {@code length} is greater than {@code this.available()}
157 */
158 public abstract Slice readSlice(int length);
159
160 @Override
161 public final void readFully(byte[] destination)
162 {
163 readBytes(destination);
164 }
165
166 @Override
167 public final int read(byte[] destination)
168 {
169 return read(destination, 0, destination.length);
170 }
171
172 @Override
173 public abstract int read(byte[] destination, int destinationIndex, int length);
174
175 /**
176 * Transfers this buffer's data to the specified destination starting at
177 * the current {@code position} and increases the {@code position}
178 * by the number of the transferred bytes (= {@code dst.length}).
179 *
180 * @throws IndexOutOfBoundsException if {@code dst.length} is greater than {@code this.available()}
181 */
182 public final void readBytes(byte[] destination)
183 {
184 readBytes(destination, 0, destination.length);
185 }
186
187 @Override
188 public final void readFully(byte[] destination, int offset, int length)
189 {
190 readBytes(destination, offset, length);
191 }
192
193 /**
194 * Transfers this buffer's data to the specified destination starting at
195 * the current {@code position} and increases the {@code position}
196 * by the number of the transferred bytes (= {@code length}).
197 *
198 * @param destinationIndex the first index of the destination
199 * @param length the number of bytes to transfer
200 * @throws IndexOutOfBoundsException if the specified {@code destinationIndex} is less than {@code 0},
201 * if {@code length} is greater than {@code this.available()}, or
202 * if {@code destinationIndex + length} is greater than {@code destination.length}
203 */
204 public abstract void readBytes(byte[] destination, int destinationIndex, int length);
205
206 /**
207 * Transfers this buffer's data to the specified destination starting at
208 * the current {@code position} until the destination becomes
209 * non-writable, and increases the {@code position} by the number of the
210 * transferred bytes. This method is basically same with
211 * {@link #readBytes(Slice, int, int)}, except that this method
212 * increases the {@code writerIndex} of the destination by the number of
213 * the transferred bytes while {@link #readBytes(Slice, int, int)}
214 * does not.
215 *
216 * @throws IndexOutOfBoundsException if {@code destination.writableBytes} is greater than
217 * {@code this.available()}
218 */
219 public final void readBytes(Slice destination)
220 {
221 readBytes(destination, 0, destination.length());
222 }
223
224 /**
225 * Transfers this buffer's data to the specified destination starting at
226 * the current {@code position} and increases the {@code position}
227 * by the number of the transferred bytes (= {@code length}). This method
228 * is basically same with {@link #readBytes(Slice, int, int)},
229 * except that this method increases the {@code writerIndex} of the
230 * destination by the number of the transferred bytes (= {@code length})
231 * while {@link #readBytes(Slice, int, int)} does not.
232 *
233 * @throws IndexOutOfBoundsException if {@code length} is greater than {@code this.available()} or
234 * if {@code length} is greater than {@code destination.writableBytes}
235 */
236 public final void readBytes(Slice destination, int length)
237 {
238 readBytes(destination, 0, length);
239 }
240
241 /**
242 * Transfers this buffer's data to the specified destination starting at
243 * the current {@code position} and increases the {@code position}
244 * by the number of the transferred bytes (= {@code length}).
245 *
246 * @param destinationIndex the first index of the destination
247 * @param length the number of bytes to transfer
248 * @throws IndexOutOfBoundsException if the specified {@code destinationIndex} is less than {@code 0},
249 * if {@code length} is greater than {@code this.available()}, or
250 * if {@code destinationIndex + length} is greater than
251 * {@code destination.capacity}
252 */
253 public abstract void readBytes(Slice destination, int destinationIndex, int length);
254
255 /**
256 * Transfers this buffer's data to the specified stream starting at the
257 * current {@code position}.
258 *
259 * @param length the number of bytes to transfer
260 * @throws IndexOutOfBoundsException if {@code length} is greater than {@code this.available()}
261 * @throws java.io.IOException if the specified stream threw an exception during I/O
262 */
263 public abstract void readBytes(OutputStream out, int length)
264 throws IOException;
265
266 @Override
267 public abstract long skip(long length);
268
269 @Override
270 public abstract int skipBytes(int length);
271
272 @Override
273 public void close()
274 {
275 }
276
277 //
278 // Unsupported operations
279 //
280
281 @Override
282 public final void mark(int readLimit)
283 {
284 throw new UnsupportedOperationException();
285 }
286
287 @Override
288 public final void reset()
289
290 {
291 throw new UnsupportedOperationException();
292 }
293
294 @Override
295 public final boolean markSupported()
296 {
297 throw new UnsupportedOperationException();
298 }
299
300 @Override
301 public final char readChar()
302 {
303 throw new UnsupportedOperationException();
304 }
305
306 @Override
307 public final String readLine()
308 {
309 throw new UnsupportedOperationException();
310 }
311
312 @Override
313 public final String readUTF()
314 {
315 throw new UnsupportedOperationException();
316 }
317 }