KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > imageio > stream > ImageInputStream


1 /*
2  * @(#)ImageInputStream.java 1.47 04/05/13
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.imageio.stream;
9
10 import java.io.DataInput JavaDoc;
11 import java.io.EOFException JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.UTFDataFormatException JavaDoc;
14 import java.nio.ByteOrder JavaDoc;
15
16 /**
17  * A seekable input stream interface for use by
18  * <code>ImageReader</code>s. Various input sources, such as
19  * <code>InputStream</code>s and <code>File</code>s,
20  * as well as future fast I/O sources may be "wrapped" by a suitable
21  * implementation of this interface for use by the Image I/O API.
22  *
23  * @see ImageInputStreamImpl
24  * @see FileImageInputStream
25  * @see FileCacheImageInputStream
26  * @see MemoryCacheImageInputStream
27  *
28  * @version 0.5
29  */

30 public interface ImageInputStream extends DataInput JavaDoc {
31
32     /**
33      * Sets the desired byte order for future reads of data values
34      * from this stream. For example, the sequence of bytes '0x01
35      * 0x02 0x03 0x04' if read as a 4-byte integer would have the
36      * value '0x01020304' using network byte order and the value
37      * '0x04030201' under the reverse byte order.
38      *
39      * <p> The enumeration class <code>java.nio.ByteOrder</code> is
40      * used to specify the byte order. A value of
41      * <code>ByteOrder.BIG_ENDIAN</code> specifies so-called
42      * big-endian or network byte order, in which the high-order byte
43      * comes first. Motorola and Sparc processors store data in this
44      * format, while Intel processors store data in the reverse
45      * <code>ByteOrder.LITTLE_ENDIAN</code> order.
46      *
47      * <p> The byte order has no effect on the results returned from
48      * the <code>readBits</code> method (or the value written by
49      * <code>ImageOutputStream.writeBits</code>).
50      *
51      * @param byteOrder one of <code>ByteOrder.BIG_ENDIAN</code> or
52      * <code>java.nio.ByteOrder.LITTLE_ENDIAN</code>, indicating whether
53      * network byte order or its reverse will be used for future
54      * reads.
55      *
56      * @see java.nio.ByteOrder
57      * @see #getByteOrder
58      * @see #readBits(int)
59      */

60     void setByteOrder(ByteOrder JavaDoc byteOrder);
61
62     /**
63      * Returns the byte order with which data values will be read from
64      * this stream as an instance of the
65      * <code>java.nio.ByteOrder</code> enumeration.
66      *
67      * @return one of <code>ByteOrder.BIG_ENDIAN</code> or
68      * <code>ByteOrder.LITTLE_ENDIAN</code>, indicating which byte
69      * order is being used.
70      *
71      * @see java.nio.ByteOrder
72      * @see #setByteOrder
73      */

74     ByteOrder JavaDoc getByteOrder();
75
76     /**
77      * Reads a single byte from the stream and returns it as an
78      * integer between 0 and 255. If the end of the stream is
79      * reached, -1 is returned.
80      *
81      * <p> The bit offset within the stream is reset to zero before
82      * the read occurs.
83      *
84      * @return a byte value from the stream, as an int, or -1 to
85      * indicate EOF.
86      *
87      * @exception IOException if an I/O error occurs.
88      */

89     int read() throws IOException JavaDoc;
90
91     /**
92      * Reads up to <code>b.length</code> bytes from the stream, and
93      * stores them into <code>b</code> starting at index 0. The
94      * number of bytes read is returned. If no bytes can be read
95      * because the end of the stream has been reached, -1 is returned.
96      *
97      * <p> The bit offset within the stream is reset to zero before
98      * the read occurs.
99      *
100      * @param b an array of bytes to be written to.
101      *
102      * @return the number of bytes actually read, or <code>-1</code>
103      * to indicate EOF.
104      *
105      * @exception NullPointerException if <code>b</code> is
106      * <code>null</code>.
107      *
108      * @exception IOException if an I/O error occurs.
109      */

110     int read(byte[] b) throws IOException JavaDoc;
111
112     /**
113      * Reads up to <code>len</code> bytes from the stream, and stores
114      * them into <code>b</code> starting at index <code>off</code>.
115      * The number of bytes read is returned. If no bytes can be read
116      * because the end of the stream has been reached, <code>-1</code>
117      * is returned.
118      *
119      * <p> The bit offset within the stream is reset to zero before
120      * the read occurs.
121      *
122      * @param b an array of bytes to be written to.
123      * @param off the starting position within <code>b</code> to write to.
124      * @param len the maximum number of <code>byte</code>s to read.
125      *
126      * @return the number of bytes actually read, or <code>-1</code>
127      * to indicate EOF.
128      *
129      * @exception NullPointerException if <code>b</code> is
130      * <code>null</code>.
131      * @exception IndexOutOfBoundsException if <code>off</code> is
132      * negative, <code>len</code> is negative, or <code>off +
133      * len</code> is greater than <code>b.length</code>.
134      * @exception IOException if an I/O error occurs.
135      */

136     int read(byte[] b, int off, int len) throws IOException JavaDoc;
137
138     /**
139      * Reads up to <code>len</code> bytes from the stream, and
140      * modifies the supplied <code>IIOByteBuffer</code> to indicate
141      * the byte array, offset, and length where the data may be found.
142      * The caller should not attempt to modify the data found in the
143      * <code>IIOByteBuffer</code>.
144      *
145      * <p> The bit offset within the stream is reset to zero before
146      * the read occurs.
147      *
148      * @param buf an IIOByteBuffer object to be modified.
149      * @param len the maximum number of <code>byte</code>s to read.
150      *
151      * @exception IndexOutOfBoundsException if <code>len</code> is
152      * negative.
153      * @exception NullPointerException if <code>buf</code> is
154      * <code>null</code>.
155      *
156      * @exception IOException if an I/O error occurs.
157      */

158     void readBytes(IIOByteBuffer JavaDoc buf, int len) throws IOException JavaDoc;
159
160     /**
161      * Reads a byte from the stream and returns a <code>boolean</code>
162      * value of <code>true</code> if it is nonzero, <code>false</code>
163      * if it is zero.
164      *
165      * <p> The bit offset within the stream is reset to zero before
166      * the read occurs.
167      *
168      * @return a boolean value from the stream.
169      *
170      * @exception EOFException if the end of the stream is reached.
171      * @exception IOException if an I/O error occurs.
172      */

173     boolean readBoolean() throws IOException JavaDoc;
174
175     /**
176      * Reads a byte from the stream and returns it as a
177      * <code>byte</code> value. Byte values between <code>0x00</code>
178      * and <code>0x7f</code> represent integer values between
179      * <code>0</code> and <code>127</code>. Values between
180      * <code>0x80</code> and <code>0xff</code> represent negative
181      * values from <code>-128</code> to <code>/1</code>.
182      *
183      * <p> The bit offset within the stream is reset to zero before
184      * the read occurs.
185      *
186      * @return a signed byte value from the stream.
187      *
188      * @exception EOFException if the end of the stream is reached.
189      * @exception IOException if an I/O error occurs.
190      */

191     byte readByte() throws IOException JavaDoc;
192     
193     /**
194      * Reads a byte from the stream, and (conceptually) converts it to
195      * an int, masks it with <code>0xff</code> in order to strip off
196      * any sign-extension bits, and returns it as a <code>byte</code>
197      * value.
198      *
199      * <p> Thus, byte values between <code>0x00</code> and
200      * <code>0x7f</code> are simply returned as integer values between
201      * <code>0</code> and <code>127</code>. Values between
202      * <code>0x80</code> and <code>0xff</code>, which normally
203      * represent negative <code>byte</code>values, will be mapped into
204      * positive integers between <code>128</code> and
205      * <code>255</code>.
206      *
207      * <p> The bit offset within the stream is reset to zero before
208      * the read occurs.
209      *
210      * @return an unsigned byte value from the stream.
211      *
212      * @exception EOFException if the end of the stream is reached.
213      * @exception IOException if an I/O error occurs.
214      */

215     int readUnsignedByte() throws IOException JavaDoc;
216
217     /**
218      * Reads two bytes from the stream, and (conceptually)
219      * concatenates them according to the current byte order, and
220      * returns the result as a <code>short</code> value.
221      *
222      * <p> The bit offset within the stream is reset to zero before
223      * the read occurs.
224      *
225      * @return a signed short value from the stream.
226      *
227      * @exception EOFException if the stream reaches the end before
228      * reading all the bytes.
229      * @exception IOException if an I/O error occurs.
230      *
231      * @see #getByteOrder
232      */

233     short readShort() throws IOException JavaDoc;
234
235     /**
236      * Reads two bytes from the stream, and (conceptually)
237      * concatenates them according to the current byte order, converts
238      * the resulting value to an <code>int</code>, masks it with
239      * <code>0xffff</code> in order to strip off any sign-extension
240      * buts, and returns the result as an unsigned <code>int</code>
241      * value.
242      *
243      * <p> The bit offset within the stream is reset to zero before
244      * the read occurs.
245      *
246      * @return an unsigned short value from the stream, as an int.
247      *
248      * @exception EOFException if the stream reaches the end before
249      * reading all the bytes.
250      * @exception IOException if an I/O error occurs.
251      *
252      * @see #getByteOrder
253      */

254     int readUnsignedShort() throws IOException JavaDoc;
255
256     /**
257      * Equivalent to <code>readUnsignedShort</code>, except that the
258      * result is returned using the <code>char</code> datatype.
259      *
260      * <p> The bit offset within the stream is reset to zero before
261      * the read occurs.
262      *
263      * @return an unsigned char value from the stream.
264      *
265      * @exception EOFException if the stream reaches the end before
266      * reading all the bytes.
267      * @exception IOException if an I/O error occurs.
268      *
269      * @see #readUnsignedShort
270      */

271     char readChar() throws IOException JavaDoc;
272
273     /**
274      * Reads 4 bytes from the stream, and (conceptually) concatenates
275      * them according to the current byte order and returns the result
276      * as an <code>int</code>.
277      *
278      * <p> The bit offset within the stream is ignored and treated as
279      * though it were zero.
280      *
281      * @return a signed int value from the stream.
282      *
283      * @exception EOFException if the stream reaches the end before
284      * reading all the bytes.
285      * @exception IOException if an I/O error occurs.
286      *
287      * @see #getByteOrder
288      */

289     int readInt() throws IOException JavaDoc;
290
291     /**
292      * Reads 4 bytes from the stream, and (conceptually) concatenates
293      * them according to the current byte order, converts the result
294      * to a long, masks it with <code>0xffffffffL</code> in order to
295      * strip off any sign-extension bits, and returns the result as an
296      * unsigned <code>long</code> value.
297      *
298      * <p> The bit offset within the stream is reset to zero before
299      * the read occurs.
300      *
301      * @return an unsigned int value from the stream, as a long.
302      *
303      * @exception EOFException if the stream reaches the end before
304      * reading all the bytes.
305      * @exception IOException if an I/O error occurs.
306      *
307      * @see #getByteOrder
308      */

309     long readUnsignedInt() throws IOException JavaDoc;
310
311     /**
312      * Reads 8 bytes from the stream, and (conceptually) concatenates
313      * them according to the current byte order and returns the result
314      * as a <code>long</code>.
315      *
316      * <p> The bit offset within the stream is reset to zero before
317      * the read occurs.
318      *
319      * @return a signed long value from the stream.
320      *
321      * @exception EOFException if the stream reaches the end before
322      * reading all the bytes.
323      * @exception IOException if an I/O error occurs.
324      *
325      * @see #getByteOrder
326      */

327     long readLong() throws IOException JavaDoc;
328
329     /**
330      * Reads 4 bytes from the stream, and (conceptually) concatenates
331      * them according to the current byte order and returns the result
332      * as a <code>float</code>.
333      *
334      * <p> The bit offset within the stream is reset to zero before
335      * the read occurs.
336      *
337      * @return a float value from the stream.
338      *
339      * @exception EOFException if the stream reaches the end before
340      * reading all the bytes.
341      * @exception IOException if an I/O error occurs.
342      *
343      * @see #getByteOrder
344      */

345     float readFloat() throws IOException JavaDoc;
346
347     /**
348      * Reads 8 bytes from the stream, and (conceptually) concatenates
349      * them according to the current byte order and returns the result
350      * as a <code>double</code>.
351      *
352      * <p> The bit offset within the stream is reset to zero before
353      * the read occurs.
354      *
355      * @return a double value from the stream.
356      *
357      * @exception EOFException if the stream reaches the end before
358      * reading all the bytes.
359      * @exception IOException if an I/O error occurs.
360      *
361      * @see #getByteOrder
362      */

363     double readDouble() throws IOException JavaDoc;
364
365     /**
366      * Reads the next line of text from the input stream. It reads
367      * successive bytes, converting each byte separately into a
368      * character, until it encounters a line terminator or end of
369      * file; the characters read are then returned as a
370      * <code>String</code>. Note that because this method processes
371      * bytes, it does not support input of the full Unicode character
372      * set.
373      *
374      * <p> If end of file is encountered before even one byte can be
375      * read, then <code>null</code> is returned. Otherwise, each byte
376      * that is read is converted to type <code>char</code> by
377      * zero-extension. If the character <code>'\n'</code> is
378      * encountered, it is discarded and reading ceases. If the
379      * character <code>'\r'</code> is encountered, it is discarded
380      * and, if the following byte converts &#32;to the character
381      * <code>'\n'</code>, then that is discarded also; reading then
382      * ceases. If end of file is encountered before either of the
383      * characters <code>'\n'</code> and <code>'\r'</code> is
384      * encountered, reading ceases. Once reading has ceased, a
385      * <code>String</code> is returned that contains all the
386      * characters read and not discarded, taken in order. Note that
387      * every character in this string will have a value less than
388      * <code>&#92;u0100</code>, that is, <code>(char)256</code>.
389      *
390      * <p> The bit offset within the stream is reset to zero before
391      * the read occurs.
392      *
393      * @return a String containing a line of text from the stream.
394      *
395      * @exception IOException if an I/O error occurs.
396      */

397     String JavaDoc readLine() throws IOException JavaDoc;
398
399     /**
400      * Reads in a string that has been encoded using a
401      * <a HREF="../../../java/io/DataInput.html#modified-utf-8">modified
402      * UTF-8</a>
403      * format. The general contract of <code>readUTF</code> is that
404      * it reads a representation of a Unicode character string encoded
405      * in modified UTF-8 format; this string of characters is
406      * then returned as a <code>String</code>.
407      *
408      * <p> First, two bytes are read and used to construct an unsigned
409      * 16-bit integer in the manner of the
410      * <code>readUnsignedShort</code> method, using network byte order
411      * (regardless of the current byte order setting). This integer
412      * value is called the <i>UTF length</i> and specifies the number
413      * of additional bytes to be read. These bytes are then converted
414      * to characters by considering them in groups. The length of each
415      * group is computed from the value of the first byte of the
416      * group. The byte following a group, if any, is the first byte of
417      * the next group.
418      *
419      * <p> If the first byte of a group matches the bit pattern
420      * <code>0xxxxxxx</code> (where <code>x</code> means "may be
421      * <code>0</code> or <code>1</code>"), then the group consists of
422      * just that byte. The byte is zero-extended to form a character.
423      *
424      * <p> If the first byte of a group matches the bit pattern
425      * <code>110xxxxx</code>, then the group consists of that byte
426      * <code>a</code> and a second byte <code>b</code>. If there is no
427      * byte <code>b</code> (because byte <code>a</code> was the last
428      * of the bytes to be read), or if byte <code>b</code> does not
429      * match the bit pattern <code>10xxxxxx</code>, then a
430      * <code>UTFDataFormatException</code> is thrown. Otherwise, the
431      * group is converted to the character:
432      *
433      * <p> <pre><code>
434      * (char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F))
435      * </code></pre>
436      *
437      * If the first byte of a group matches the bit pattern
438      * <code>1110xxxx</code>, then the group consists of that byte
439      * <code>a</code> and two more bytes <code>b</code> and
440      * <code>c</code>. If there is no byte <code>c</code> (because
441      * byte <code>a</code> was one of the last two of the bytes to be
442      * read), or either byte <code>b</code> or byte <code>c</code>
443      * does not match the bit pattern <code>10xxxxxx</code>, then a
444      * <code>UTFDataFormatException</code> is thrown. Otherwise, the
445      * group is converted to the character:
446      *
447      * <p> <pre><code>
448      * (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F))
449      * </code></pre>
450      *
451      * If the first byte of a group matches the pattern
452      * <code>1111xxxx</code> or the pattern <code>10xxxxxx</code>,
453      * then a <code>UTFDataFormatException</code> is thrown.
454      *
455      * <p> If end of file is encountered at any time during this
456      * entire process, then an <code>EOFException</code> is thrown.
457      *
458      * <p> After every group has been converted to a character by this
459      * process, the characters are gathered, in the same order in
460      * which their corresponding groups were read from the input
461      * stream, to form a <code>String</code>, which is returned.
462      *
463      * <p> The current byte order setting is ignored.
464      *
465      * <p> The bit offset within the stream is reset to zero before
466      * the read occurs.
467      *
468      * <p><strong>Note:</strong> This method should not be used in
469      * the implementation of image formats that use standard UTF-8,
470      * because the modified UTF-8 used here is incompatible with
471      * standard UTF-8.
472      *
473      * @return a String read from the stream.
474      *
475      * @exception EOFException if this stream reaches the end
476      * before reading all the bytes.
477      * @exception UTFDataFormatException if the bytes do not represent a
478      * valid modified UTF-8 encoding of a string.
479      * @exception IOException if an I/O error occurs.
480      */

481     String JavaDoc readUTF() throws IOException JavaDoc;
482
483     /**
484      * Reads <code>len</code> bytes from the stream, and stores them
485      * into <code>b</code> starting at index <code>off</code>.
486      * If the end of the stream is reached, an <code>EOFException</code>
487      * will be thrown.
488      *
489      * <p> The bit offset within the stream is reset to zero before
490      * the read occurs.
491      *
492      * @param b an array of bytes to be written to.
493      * @param off the starting position within <code>b</code> to write to.
494      * @param len the maximum number of <code>byte</code>s to read.
495      *
496      * @exception IndexOutOfBoundsException if <code>off</code> is
497      * negative, <code>len</code> is negative, or <code>off +
498      * len</code> is greater than <code>b.length</code>.
499      * @exception NullPointerException if <code>b</code> is
500      * <code>null</code>.
501      * @exception EOFException if the stream reaches the end before
502      * reading all the bytes.
503      * @exception IOException if an I/O error occurs.
504      */

505     void readFully(byte[] b, int off, int len) throws IOException JavaDoc;
506
507     /**
508      * Reads <code>b.length</code> bytes from the stream, and stores them
509      * into <code>b</code> starting at index <code>0</code>.
510      * If the end of the stream is reached, an <code>EOFException</code>
511      * will be thrown.
512      *
513      * <p> The bit offset within the stream is reset to zero before
514      * the read occurs.
515      *
516      * @param b an array of <code>byte</code>s.
517      *
518      * @exception NullPointerException if <code>b</code> is
519      * <code>null</code>.
520      * @exception EOFException if the stream reaches the end before
521      * reading all the bytes.
522      * @exception IOException if an I/O error occurs.
523      */

524     void readFully(byte[] b) throws IOException JavaDoc;
525
526     /**
527      * Reads <code>len</code> shorts (signed 16-bit integers) from the
528      * stream according to the current byte order, and
529      * stores them into <code>s</code> starting at index
530      * <code>off</code>. If the end of the stream is reached, an
531      * <code>EOFException</code> will be thrown.
532      *
533      * <p> The bit offset within the stream is reset to zero before
534      * the read occurs.
535      *
536      * @param s an array of shorts to be written to.
537      * @param off the starting position withinb to write to.
538      * @param len the maximum number of <code>short</code>s to read.
539      *
540      * @exception IndexOutOfBoundsException if <code>off</code> is
541      * negative, <code>len</code> is negative, or <code>off +
542      * len</code> is greater than <code>s.length</code>.
543      * @exception NullPointerException if <code>s</code> is
544      * <code>null</code>.
545      * @exception EOFException if the stream reaches the end before
546      * reading all the bytes.
547      * @exception IOException if an I/O error occurs.
548      */

549     void readFully(short[] s, int off, int len) throws IOException JavaDoc;
550
551     /**
552      * Reads <code>len</code> chars (unsigned 16-bit integers) from the
553      * stream according to the current byte order, and
554      * stores them into <code>c</code> starting at index
555      * <code>off</code>. If the end of the stream is reached, an
556      * <code>EOFException</code> will be thrown.
557      *
558      * <p> The bit offset within the stream is reset to zero before
559      * the read occurs.
560      *
561      * @param c an array of chars to be written to.
562      * @param off the starting position withinb to write to.
563      * @param len the maximum number of <code>char</code>s to read.
564      *
565      * @exception IndexOutOfBoundsException if <code>off</code> is
566      * negative, <code>len</code> is negative, or <code>off +
567      * len</code> is greater than <code>c.length</code>.
568      * @exception NullPointerException if <code>c</code> is
569      * <code>null</code>.
570      * @exception EOFException if the stream reaches the end before
571      * reading all the bytes.
572      * @exception IOException if an I/O error occurs.
573      */

574     void readFully(char[] c, int off, int len) throws IOException JavaDoc;
575
576     /**
577      * Reads <code>len</code> ints (signed 32-bit integers) from the
578      * stream according to the current byte order, and
579      * stores them into <code>i</code> starting at index
580      * <code>off</code>. If the end of the stream is reached, an
581      * <code>EOFException</code> will be thrown.
582      *
583      * <p> The bit offset within the stream is reset to zero before
584      * the read occurs.
585      *
586      * @param i an array of ints to be written to.
587      * @param off the starting position withinb to write to.
588      * @param len the maximum number of <code>int</code>s to read.
589      *
590      * @exception IndexOutOfBoundsException if <code>off</code> is
591      * negative, <code>len</code> is negative, or <code>off +
592      * len</code> is greater than <code>i.length</code>.
593      * @exception NullPointerException if <code>i</code> is
594      * <code>null</code>.
595      * @exception EOFException if the stream reaches the end before
596      * reading all the bytes.
597      * @exception IOException if an I/O error occurs.
598      */

599     void readFully(int[] i, int off, int len) throws IOException JavaDoc;
600
601     /**
602      * Reads <code>len</code> longs (signed 64-bit integers) from the
603      * stream according to the current byte order, and
604      * stores them into <code>l</code> starting at index
605      * <code>off</code>. If the end of the stream is reached, an
606      * <code>EOFException</code> will be thrown.
607      *
608      * <p> The bit offset within the stream is reset to zero before
609      * the read occurs.
610      *
611      * @param l an array of longs to be written to.
612      * @param off the starting position withinb to write to.
613      * @param len the maximum number of <code>long</code>s to read.
614      *
615      * @exception IndexOutOfBoundsException if <code>off</code> is
616      * negative, <code>len</code> is negative, or <code>off +
617      * len</code> is greater than <code>l.length</code>.
618      * @exception NullPointerException if <code>l</code> is
619      * <code>null</code>.
620      * @exception EOFException if the stream reaches the end before
621      * reading all the bytes.
622      * @exception IOException if an I/O error occurs.
623      */

624     void readFully(long[] l, int off, int len) throws IOException JavaDoc;
625
626     /**
627      * Reads <code>len</code> floats (32-bit IEEE single-precision
628      * floats) from the stream according to the current byte order,
629      * and stores them into <code>f</code> starting at
630      * index <code>off</code>. If the end of the stream is reached,
631      * an <code>EOFException</code> will be thrown.
632      *
633      * <p> The bit offset within the stream is reset to zero before
634      * the read occurs.
635      *
636      * @param f an array of floats to be written to.
637      * @param off the starting position withinb to write to.
638      * @param len the maximum number of <code>float</code>s to read.
639      *
640      * @exception IndexOutOfBoundsException if <code>off</code> is
641      * negative, <code>len</code> is negative, or <code>off +
642      * len</code> is greater than <code>f.length</code>.
643      * @exception NullPointerException if <code>f</code> is
644      * <code>null</code>.
645      * @exception EOFException if the stream reaches the end before
646      * reading all the bytes.
647      * @exception IOException if an I/O error occurs.
648      */

649     void readFully(float[] f, int off, int len) throws IOException JavaDoc;
650
651     /**
652      * Reads <code>len</code> doubles (64-bit IEEE double-precision
653      * floats) from the stream according to the current byte order,
654      * and stores them into <code>d</code> starting at
655      * index <code>off</code>. If the end of the stream is reached,
656      * an <code>EOFException</code> will be thrown.
657      *
658      * <p> The bit offset within the stream is reset to zero before
659      * the read occurs.
660      *
661      * @param d an array of doubles to be written to.
662      * @param off the starting position withinb to write to.
663      * @param len the maximum number of <code>double</code>s to read.
664      *
665      * @exception IndexOutOfBoundsException if <code>off</code> is
666      * negative, <code>len</code> is negative, or <code>off +
667      * len</code> is greater than <code>d.length</code>.
668      * @exception NullPointerException if <code>d</code> is
669      * <code>null</code>.
670      * @exception EOFException if the stream reaches the end before
671      * reading all the bytes.
672      * @exception IOException if an I/O error occurs.
673      */

674     void readFully(double[] d, int off, int len) throws IOException JavaDoc;
675
676     /**
677      * Returns the current byte position of the stream. The next read
678      * will take place starting at this offset.
679      *
680      * @return a long containing the position of the stream.
681      *
682      * @exception IOException if an I/O error occurs.
683      */

684     long getStreamPosition() throws IOException JavaDoc;
685
686     /**
687      * Returns the current bit offset, as an integer between 0 and 7,
688      * inclusive. The bit offset is updated implicitly by calls to
689      * the <code>readBits</code> method. A value of 0 indicates the
690      * most-significant bit, and a value of 7 indicates the least
691      * significant bit, of the byte being read.
692      *
693      * <p> The bit offset is set to 0 when a stream is first
694      * opened, and is reset to 0 by calls to <code>seek</code>,
695      * <code>skipBytes</code>, or any <code>read</code> or
696      * <code>readFully</code> method.
697      *
698      * @return an <code>int</code> containing the bit offset between
699      * 0 and 7, inclusive.
700      *
701      * @exception IOException if an I/O error occurs.
702      *
703      * @see #setBitOffset
704      */

705     int getBitOffset() throws IOException JavaDoc;
706
707     /**
708      * Sets the bit offset to an integer between 0 and 7, inclusive.
709      * The byte offset within the stream, as returned by
710      * <code>getStreamPosition</code>, is left unchanged.
711      * A value of 0 indicates the
712      * most-significant bit, and a value of 7 indicates the least
713      * significant bit, of the byte being read.
714      *
715      * @param bitOffset the desired offset, as an <code>int</code>
716      * between 0 and 7, inclusive.
717      *
718      * @exception IllegalArgumentException if <code>bitOffset</code>
719      * is not between 0 and 7, inclusive.
720      * @exception IOException if an I/O error occurs.
721      *
722      * @see #getBitOffset
723      */

724     void setBitOffset(int bitOffset) throws IOException JavaDoc;
725
726     /**
727      * Reads a single bit from the stream and returns it as an
728      * <code>int</code> with the value <code>0</code> or
729      * <code>1</code>. The bit offset is advanced by one and reduced
730      * modulo 8.
731      *
732      * @return an <code>int</code> containing the value <code>0</code>
733      * or <code>1</code>.
734      *
735      * @exception EOFException if the stream reaches the end before
736      * reading all the bits.
737      * @exception IOException if an I/O error occurs.
738      */

739     int readBit() throws IOException JavaDoc;
740
741     /**
742      * Reads a bitstring from the stream and returns it as a
743      * <code>long</code>, with the first bit read becoming the most
744      * significant bit of the output. The read starts within the byte
745      * indicated by <code>getStreamPosition</code>, at the bit given
746      * by <code>getBitOffset</code>. The bit offset is advanced by
747      * <code>numBits</code> and reduced modulo 8.
748      *
749      * <p> The byte order of the stream has no effect on this
750      * method. The return value of this method is constructed as
751      * though the bits were read one at a time, and shifted into
752      * the right side of the return value, as shown by the following
753      * pseudo-code:
754      *
755      * <pre>
756      * long accum = 0L;
757      * for (int i = 0; i < numBits; i++) {
758      * accum <<= 1; // Shift left one bit to make room
759      * accum |= readBit();
760      * }
761      * </pre>
762      *
763      * Note that the result of <code>readBits(32)</code> may thus not
764      * be equal to that of <code>readInt()</code> if a reverse network
765      * byte order is being used (i.e., <code>getByteOrder() ==
766      * false</code>).
767      *
768      * <p> If the end of the stream is encountered before all the bits
769      * have been read, an <code>EOFException</code> is thrown.
770      *
771      * @param numBits the number of bits to read, as an <code>int</code>
772      * between 0 and 64, inclusive.
773      * @return the bitstring, as a <code>long</code> with the last bit
774      * read stored in the least significant bit.
775      *
776      * @exception IllegalArgumentException if <code>numBits</code>
777      * is not between 0 and 64, inclusive.
778      * @exception EOFException if the stream reaches the end before
779      * reading all the bits.
780      * @exception IOException if an I/O error occurs.
781      */

782     long readBits(int numBits) throws IOException JavaDoc;
783
784     /**
785      * Returns the total length of the stream, if known. Otherwise,
786      * <code>-1</code> is returned.
787      *
788      * @return a <code>long</code> containing the length of the
789      * stream, if known, or else <code>-1</code>.
790      *
791      * @exception IOException if an I/O error occurs.
792      */

793     long length() throws IOException JavaDoc;
794
795     /**
796      * Moves the stream position forward by a given number of bytes. It
797      * is possible that this method will only be able to skip forward
798      * by a smaller number of bytes than requested, for example if the
799      * end of the stream is reached. In all cases, the actual number
800      * of bytes skipped is returned. The bit offset is set to zero
801      * prior to advancing the position.
802      *
803      * @param n an <code>int</code> containing the number of bytes to
804      * be skipped.
805      *
806      * @return an <code>int</code> representing the number of bytes skipped.
807      *
808      * @exception IOException if an I/O error occurs.
809      */

810     int skipBytes(int n) throws IOException JavaDoc;
811
812     /**
813      * Moves the stream position forward by a given number of bytes.
814      * This method is identical to <code>skipBytes(int)</code> except
815      * that it allows for a larger skip distance.
816      *
817      * @param n a <code>long</code> containing the number of bytes to
818      * be skipped.
819      *
820      * @return a <code>long</code> representing the number of bytes
821      * skipped.
822      *
823      * @exception IOException if an I/O error occurs.
824      */

825     long skipBytes(long n) throws IOException JavaDoc;
826
827     /**
828      * Sets the current stream position to the desired location. The
829      * next read will occur at this location. The bit offset is set
830      * to 0.
831      *
832      * <p> An <code>IndexOutOfBoundsException</code> will be thrown if
833      * <code>pos</code> is smaller than the flushed position (as
834      * returned by <code>getflushedPosition</code>).
835      *
836      * <p> It is legal to seek past the end of the file; an
837      * <code>EOFException</code> will be thrown only if a read is
838      * performed.
839      *
840      * @param pos a <code>long</code> containing the desired file
841      * pointer position.
842      *
843      * @exception IndexOutOfBoundsException if <code>pos</code> is smaller
844      * than the flushed position.
845      * @exception IOException if any other I/O error occurs.
846      */

847     void seek(long pos) throws IOException JavaDoc;
848
849     /**
850      * Marks a position in the stream to be returned to by a
851      * subsequent call to <code>reset</code>. Unlike a standard
852      * <code>InputStream</code>, all <code>ImageInputStream</code>s
853      * support marking. Additionally, calls to <code>mark</code> and
854      * <code>reset</code> may be nested arbitrarily.
855      *
856      * <p> Unlike the <code>mark</code> methods declared by the
857      * <code>Reader</code> <code>InputStream</code> interfaces, no
858      * <code>readLimit</code> parameter is used. An arbitrary amount
859      * of data may be read following the call to <code>mark</code>.
860      *
861      * <p> The bit position used by the <code>readBits</code> method
862      * is saved and restored by each pair of calls to
863      * <code>mark</code> and <code>reset</code>.
864      */

865     void mark();
866
867     /**
868      * Returns the file pointer to its previous position, including
869      * the bit offset, at the time of the most recent unmatched call
870      * to <code>mark</code>.
871      *
872      * <p> Calls to <code>reset</code> without a corresponding call
873      * to <code>mark</code> have no effect.
874      *
875      * <p> An <code>IOException</code> will be thrown if the previous
876      * marked position lies in the discarded portion of the stream.
877      *
878      * @exception IOException if an I/O error occurs.
879      */

880     void reset() throws IOException JavaDoc;
881
882     /**
883      * Discards the initial portion of the stream prior to the
884      * indicated postion. Attempting to seek to an offset within the
885      * flushed portion of the stream will result in an
886      * <code>IndexOutOfBoundsException</code>.
887      *
888      * <p> Calling <code>flushBefore</code> may allow classes
889      * implementing this interface to free up resources such as memory
890      * or disk space that are being used to store data from the
891      * stream.
892      *
893      * @param pos a <code>long</code> containing the length of the
894      * file prefix that may be flushed.
895      *
896      * @exception IndexOutOfBoundsException if <code>pos</code> lies
897      * in the flushed portion of the stream or past the current stream
898      * position.
899      * @exception IOException if an I/O error occurs.
900      */

901     void flushBefore(long pos) throws IOException JavaDoc;
902
903     /**
904      * Discards the initial position of the stream prior to the current
905      * stream position. Equivalent to
906      * <code>flushBefore(getStreamPosition())</code>.
907      *
908      * @exception IOException if an I/O error occurs.
909      */

910     void flush() throws IOException JavaDoc;
911
912     /**
913      * Returns the earliest position in the stream to which seeking
914      * may be performed. The returned value will be the maximum of
915      * all values passed into previous calls to
916      * <code>flushBefore</code>.
917      *
918      * @return the earliest legal position for seeking, as a
919      * <code>long</code>.
920      */

921     long getFlushedPosition();
922
923     /**
924      * Returns <code>true</code> if this <code>ImageInputStream</code>
925      * caches data itself in order to allow seeking backwards.
926      * Applications may consult this in order to decide how frequently,
927      * or whether, to flush in order to conserve cache resources.
928      *
929      * @return <code>true</code> if this <code>ImageInputStream</code>
930      * caches data.
931      *
932      * @see #isCachedMemory
933      * @see #isCachedFile
934      */

935     boolean isCached();
936
937     /**
938      * Returns <code>true</code> if this <code>ImageInputStream</code>
939      * caches data itself in order to allow seeking backwards, and
940      * the cache is kept in main memory. Applications may consult
941      * this in order to decide how frequently, or whether, to flush
942      * in order to conserve cache resources.
943      *
944      * @return <code>true</code> if this <code>ImageInputStream</code>
945      * caches data in main memory.
946      *
947      * @see #isCached
948      * @see #isCachedFile
949      */

950     boolean isCachedMemory();
951
952     /**
953      * Returns <code>true</code> if this <code>ImageInputStream</code>
954      * caches data itself in order to allow seeking backwards, and
955      * the cache is kept in a temporary file. Applications may consult
956      * this in order to decide how frequently, or whether, to flush
957      * in order to conserve cache resources.
958      *
959      * @return <code>true</code> if this <code>ImageInputStream</code>
960      * caches data in a temporary file.
961      *
962      * @see #isCached
963      * @see #isCachedMemory
964      */

965     boolean isCachedFile();
966
967     /**
968      * Closes the stream. Attempts to access a stream that has been
969      * closed may result in <code>IOException</code>s or incorrect
970      * behavior. Calling this method may allow classes implementing
971      * this interface to release resources associated with the stream
972      * such as memory, disk space, or file descriptors.
973      *
974      * @exception IOException if an I/O error occurs.
975      */

976     void close() throws IOException JavaDoc;
977 }
978
Popular Tags