blob: 771e9ff96c47b861483ff5e9c387ac08a956c2d1 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @author Rustem V. Rafikov
19 * @version $Revision: 1.2 $
20 */
21package javax.imageio.stream;
22
23import java.io.DataInput;
24import java.io.IOException;
25import java.nio.ByteOrder;
26
27/**
28 * The ImageInputStream represents input stream interface that is
29 * used by ImageReaders.
30 */
31public interface ImageInputStream extends DataInput {
32
33 /**
34 * Sets the specified byte order for reading of data values
35 * from this stream.
36 *
37 * @param byteOrder the byte order.
38 */
39 void setByteOrder(ByteOrder byteOrder);
40
41 /**
42 * Gets the byte order.
43 *
44 * @return the byte order.
45 */
46 ByteOrder getByteOrder();
47
48 /**
49 * Reads a byte from the stream.
50 *
51 * @return the byte of the stream, or -1 for EOF indicating.
52 *
53 * @throws IOException Signals that an I/O exception has occurred.
54 */
55 int read() throws IOException;
56
57 /**
58 * Reads number of bytes which is equal to the specified array's length
59 * and stores a result to this array.
60 *
61 * @param b the byte array.
62 *
63 * @return the number of read bytes, or -1 indicated EOF.
64 *
65 * @throws IOException Signals that an I/O exception has occurred.
66 */
67 int read(byte[] b) throws IOException;
68
69 /**
70 * Reads the number of bytes specified by len parameter from
71 * the stream and stores a result to the specified array
72 * with the specified offset.
73 *
74 * @param b the byte array.
75 * @param off the offset.
76 * @param len the number of bytes to be read.
77 *
78 * @return the number of read bytes, or -1 indicated EOF.
79 *
80 * @throws IOException Signals that an I/O exception has occurred.
81 */
82 int read(byte[] b, int off, int len) throws IOException;
83
84 /**
85 * Reads the number of bytes specified by len parameter
86 * from the stream, and modifies the specified IIOByteBuffer
87 * with the byte array, offset, and length.
88 *
89 * @param buf the IIOByteBuffer.
90 * @param len the number of bytes to be read.
91 *
92 * @throws IOException Signals that an I/O exception has occurred.
93 */
94 void readBytes(IIOByteBuffer buf, int len) throws IOException;
95
96 /**
97 * Reads a byte from the stream and returns a boolean true value
98 * if it is non zero, false if it is zero.
99 *
100 * @return a boolean value for read byte.
101 *
102 * @throws IOException Signals that an I/O exception has occurred.
103 */
104 boolean readBoolean() throws IOException;
105
106 /**
107 * Reads a byte from the stream and returns its value
108 * as signed byte.
109 *
110 * @return a signed byte value for read byte.
111 *
112 * @throws IOException Signals that an I/O exception has occurred.
113 */
114 byte readByte() throws IOException;
115
116 /**
117 * Reads a byte from the stream and returns its value
118 * as int.
119 *
120 * @return a unsigned byte value for read byte as int.
121 *
122 * @throws IOException Signals that an I/O exception has occurred.
123 */
124 int readUnsignedByte() throws IOException;
125
126 /**
127 * Reads 2 bytes from the stream, and returns the result
128 * as a short.
129 *
130 * @return the signed short value from the stream.
131 *
132 * @throws IOException Signals that an I/O exception has occurred.
133 */
134 short readShort() throws IOException;
135
136 /**
137 * Reads 2 bytes from the stream and returns its value
138 * as an unsigned short.
139 *
140 * @return a unsigned short value coded in an int.
141 *
142 * @throws IOException Signals that an I/O exception has occurred.
143 */
144 int readUnsignedShort() throws IOException;
145
146 /**
147 * Reads 2 bytes from the stream and returns their
148 * unsigned char value.
149 *
150 * @return the unsigned char value.
151 *
152 * @throws IOException Signals that an I/O exception has occurred.
153 */
154 char readChar() throws IOException;
155
156 /**
157 * Reads 4 bytes from the stream, and returns the result
158 * as an int.
159 *
160 * @return the signed int value from the stream.
161 *
162 * @throws IOException Signals that an I/O exception has occurred.
163 */
164 int readInt() throws IOException;
165
166 /**
167 * Reads 4 bytes from the stream and returns its value
168 * as long.
169 *
170 * @return a unsigned int value as long.
171 *
172 * @throws IOException Signals that an I/O exception has occurred.
173 */
174 long readUnsignedInt() throws IOException;
175
176 /**
177 * Reads 8 bytes from the stream, and returns the result
178 * as a long.
179 *
180 * @return the long value from the stream.
181 *
182 * @throws IOException Signals that an I/O exception has occurred.
183 */
184 long readLong() throws IOException;
185
186 /**
187 * Reads 4 bytes from the stream, and returns the result
188 * as a float.
189 *
190 * @return the float value from the stream.
191 *
192 * @throws IOException Signals that an I/O exception has occurred.
193 */
194 float readFloat() throws IOException;
195
196 /**
197 * Reads 8 bytes from the stream, and returns the result
198 * as a double.
199 *
200 * @return the double value from the stream.
201 *
202 * @throws IOException Signals that an I/O exception has occurred.
203 */
204 double readDouble() throws IOException;
205
206 /**
207 * Reads a line from the stream.
208 *
209 * @return the string contained the line from the stream.
210 *
211 * @throws IOException Signals that an I/O exception has occurred.
212 */
213 String readLine() throws IOException;
214
215 /**
216 * Reads bytes from the stream in a string that has been encoded
217 * in a modified UTF-8 format.
218 *
219 * @return the string read from stream and modified UTF-8 format.
220 *
221 * @throws IOException Signals that an I/O exception has occurred.
222 */
223 String readUTF() throws IOException;
224
225 /**
226 * Reads the specified number of bytes from the stream,
227 * and stores the result into the specified array starting at
228 * the specified index offset.
229 *
230 * @param b the byte array.
231 * @param off the offset.
232 * @param len the number of bytes to be read.
233 *
234 * @throws IOException Signals that an I/O exception has occurred.
235 */
236 void readFully(byte[] b, int off, int len) throws IOException;
237
238 /**
239 * Reads number of bytes from the stream which is equal to
240 * the specified array's length, and stores them into
241 * this array.
242 *
243 * @param b the byte array.
244 *
245 * @throws IOException Signals that an I/O exception has occurred.
246 */
247 void readFully(byte[] b) throws IOException;
248
249 /**
250 * Reads the specified number of shorts from the stream,
251 * and stores the result into the specified array starting at
252 * the specified index offset.
253 *
254 * @param s the short array.
255 * @param off the offset.
256 * @param len the number of shorts to be read.
257 *
258 * @throws IOException Signals that an I/O exception has occurred.
259 */
260 void readFully(short[] s, int off, int len) throws IOException;
261
262 /**
263 * Reads the specified number of chars from the stream,
264 * and stores the result into the specified array starting at
265 * the specified index offset.
266 *
267 * @param c the char array.
268 * @param off the offset.
269 * @param len the number of chars to be read.
270 *
271 * @throws IOException Signals that an I/O exception has occurred.
272 */
273 void readFully(char[] c, int off, int len) throws IOException;
274
275 /**
276 * Reads the specified number of ints from the stream,
277 * and stores the result into the specified array starting at
278 * the specified index offset.
279 *
280 * @param i the int array.
281 * @param off the offset.
282 * @param len the number of ints to be read.
283 *
284 * @throws IOException Signals that an I/O exception has occurred.
285 */
286 void readFully(int[] i, int off, int len) throws IOException;
287
288 /**
289 * Reads the specified number of longs from the stream,
290 * and stores the result into the specified array starting at
291 * the specified index offset.
292 *
293 * @param l the long array.
294 * @param off the offset.
295 * @param len the number of longs to be read.
296 *
297 * @throws IOException Signals that an I/O exception has occurred.
298 */
299 void readFully(long[] l, int off, int len) throws IOException;
300
301 /**
302 * Reads the specified number of floats from the stream,
303 * and stores the result into the specified array starting at
304 * the specified index offset.
305 *
306 * @param f the float array.
307 * @param off the offset.
308 * @param len the number of floats to be read.
309 *
310 * @throws IOException Signals that an I/O exception has occurred.
311 */
312 void readFully(float[] f, int off, int len) throws IOException;
313
314 /**
315 * Reads the specified number of doubles from the stream,
316 * and stores the result into the specified array starting at
317 * the specified index offset.
318 *
319 * @param d the double array.
320 * @param off the offset.
321 * @param len the number of doubles to be read.
322 *
323 * @throws IOException Signals that an I/O exception has occurred.
324 */
325 void readFully(double[] d, int off, int len) throws IOException;
326
327 /**
328 * Gets the stream position.
329 *
330 * @return the stream position.
331 *
332 * @throws IOException Signals that an I/O exception has occurred.
333 */
334 long getStreamPosition() throws IOException;
335
336 /**
337 * Gets the bit offset.
338 *
339 * @return the bit offset.
340 *
341 * @throws IOException Signals that an I/O exception has occurred.
342 */
343 int getBitOffset() throws IOException;
344
345 /**
346 * Sets the bit offset to an integer between 0 and 7.
347 *
348 * @param bitOffset the bit offset.
349 *
350 * @throws IOException Signals that an I/O exception has occurred.
351 */
352 void setBitOffset(int bitOffset) throws IOException;
353
354 /**
355 * Reads a bit from the stream and returns the value 0 or 1.
356 *
357 * @return the value of single bit: 0 or 1.
358 *
359 * @throws IOException Signals that an I/O exception has occurred.
360 */
361 int readBit() throws IOException;
362
363 /**
364 * Read the specified number of bits and returns their values as long.
365 *
366 * @param numBits the number of bits to be read.
367 *
368 * @return the bit string as a long.
369 *
370 * @throws IOException Signals that an I/O exception has occurred.
371 */
372 long readBits(int numBits) throws IOException;
373
374 /**
375 * Returns the length of the stream.
376 *
377 * @return the length of the stream, or -1 if unknown.
378 *
379 * @throws IOException Signals that an I/O exception has occurred.
380 */
381 long length() throws IOException;
382
383 /**
384 * Skipes the specified number of bytes by moving stream position.
385 *
386 * @param n the number of bytes.
387 *
388 * @return the actual skipped number of bytes.
389 *
390 * @throws IOException Signals that an I/O exception has occurred.
391 */
392 int skipBytes(int n) throws IOException;
393
394 /**
395 * Skipes the specified number of bytes by moving stream position.
396 *
397 * @param n the number of bytes.
398 *
399 * @return the actual skipped number of bytes.
400 *
401 * @throws IOException Signals that an I/O exception has occurred.
402 */
403 long skipBytes(long n) throws IOException;
404
405 /**
406 * Sets the current stream position to the specified location.
407 *
408 * @param pos a file pointer position.
409 *
410 * @throws IOException Signals that an I/O exception has occurred.
411 */
412 void seek(long pos) throws IOException;
413
414 /**
415 * Marks a position in the stream to be returned to by a subsequent
416 * call to reset.
417 */
418 void mark();
419
420 /**
421 * Returns the file pointer to its previous position.
422 *
423 * @throws IOException Signals that an I/O exception has occurred.
424 */
425 void reset() throws IOException;
426
427 /**
428 * Flushes the initial position in this stream prior to the
429 * specified stream position.
430 *
431 * @param pos the position.
432 *
433 * @throws IOException Signals that an I/O exception has occurred.
434 */
435 void flushBefore(long pos) throws IOException;
436
437 /**
438 * Flushes the initial position in this stream prior to the
439 * current stream position.
440 *
441 * @throws IOException Signals that an I/O exception has occurred.
442 */
443 void flush() throws IOException;
444
445 /**
446 * Gets the flushed position.
447 *
448 * @return the flushed position.
449 */
450 long getFlushedPosition();
451
452 /**
453 * Returns true if this ImageInputStream caches data in order
454 * to allow seeking backwards.
455 *
456 * @return true if this ImageInputStream caches data in order
457 * to allow seeking backwards, false otherwise.
458 */
459 boolean isCached();
460
461 /**
462 * Returns true if this ImageInputStream caches data in order
463 * to allow seeking backwards, and keeps it in memory.
464 *
465 * @return true if this ImageInputStream caches data in order
466 * to allow seeking backwards, and keeps it in memory.
467 */
468 boolean isCachedMemory();
469
470 /**
471 * Returns true if this ImageInputStream caches data in order
472 * to allow seeking backwards, and keeps it in a temporary file.
473 *
474 * @return true if this ImageInputStream caches data in order
475 * to allow seeking backwards, and keeps it in a temporary file.
476 */
477 boolean isCachedFile();
478
479 /**
480 * Closes this stream.
481 *
482 * @throws IOException Signals that an I/O exception has occurred.
483 */
484 void close() throws IOException;
485}