ImageInputStream interface.
This class is designed to reduce the number of methods that must
be implemented by subclasses.
In particular, this class handles most or all of the details of byte order interpretation, buffering, mark/reset, discarding, closing, and disposing.
| Modifier and Type | Field and Description |
|---|---|
| protected int | bitOffset
The current bit offset within the stream. |
| private static final int | |
| pack-priv byte[] | byteBuf
Byte buffer used for readFully(type[], int, int). |
| protected ByteOrder | byteOrder
The byte order of the stream as an instance of the enumeration
class |
| protected long | flushedPos
The position prior to which data may be discarded. |
| private boolean | |
| private final Stack | |
| private final Stack | |
| protected long | streamPos
The current read position within the stream. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected final void | |
| public void | |
| public void | flush()
Implements javax. Discards the initial position of the stream prior to the current stream position. |
| public void | flushBefore(long pos)
Implements javax. Discards the initial portion of the stream prior to the indicated position. |
| public int | getBitOffset()
Implements javax. Returns the current bit offset, as an integer between 0 and 7, inclusive. |
| public ByteOrder | getByteOrder()
Implements javax. Returns the byte order with which data values will be read from
this stream as an instance of the
|
| public long | getFlushedPosition()
Implements javax. Returns the earliest position in the stream to which seeking may be performed. |
| public long | getStreamPosition()
Implements javax. Returns the current byte position of the stream. |
| public boolean | isCached()
Implements javax. Default implementation returns false. |
| public boolean | isCachedFile()
Implements javax. Default implementation returns false. |
| public boolean | isCachedMemory()
Implements javax. Default implementation returns false. |
| public long | Returns: -1L to indicate unknown length.Implements javax. Returns |
| public void | mark()
Implements javax. Pushes the current stream position onto a stack of marked positions. |
| public abstract int | Returns: the value of the next byte in the stream, or-1
if EOF is reached.Redeclares javax. Reads a single byte from the stream and returns it as an
|
| public int | Returns: the number of bytes actually read, or-1
to indicate EOF.Implements javax. A convenience method that calls |
| public abstract int | Returns: the number of bytes actually read, or-1
to indicate EOF.an array of bytes to be written to. b, int the starting position within off, int b to write to.the maximum number of bytes to read. len)Redeclares javax. Reads up to |
| public int | readBit()
Implements javax. Reads a single bit from the stream and returns it as an
|
| public long | readBits(int numBits)
Implements javax. Reads a bitstring from the stream and returns it as a
|
| public boolean | readBoolean()
Implements javax. Reads a byte from the stream and returns a |
| public byte | readByte()
Implements javax. Reads a byte from the stream and returns it as a
|
| public void | readBytes(IIOByteBuffer buf, int len)
Implements javax. Reads up to |
| public char | readChar()
Implements javax. Equivalent to |
| public double | readDouble()
Implements javax. Reads 8 bytes from the stream, and (conceptually) concatenates
them according to the current byte order and returns the result
as a |
| public float | readFloat()
Implements javax. Reads 4 bytes from the stream, and (conceptually) concatenates
them according to the current byte order and returns the result
as a |
| public void | readFully(byte[] b, int off, int len)
Implements javax. Reads |
| public void | readFully(byte[] b)
Implements javax. Reads |
| public void | readFully(short[] s, int off, int len)
Implements javax. Reads |
| public void | readFully(char[] c, int off, int len)
Implements javax. Reads |
| public void | readFully(int[] i, int off, int len)
Implements javax. Reads |
| public void | readFully(long[] l, int off, int len)
Implements javax. Reads |
| public void | readFully(float[] f, int off, int len)
Implements javax. Reads |
| public void | readFully(double[] d, int off, int len)
Implements javax. Reads |
| public int | readInt()
Implements javax. Reads 4 bytes from the stream, and (conceptually) concatenates
them according to the current byte order and returns the result
as an |
| public String | readLine()
Implements javax. Reads the next line of text from the input stream. |
| public long | readLong()
Implements javax. Reads 8 bytes from the stream, and (conceptually) concatenates
them according to the current byte order and returns the result
as a |
| public short | readShort()
Implements javax. Reads two bytes from the stream, and (conceptually)
concatenates them according to the current byte order, and
returns the result as a |
| public int | readUnsignedByte()
Implements javax. Reads a byte from the stream, and (conceptually) converts it to
an int, masks it with |
| public long | readUnsignedInt()
Implements javax. Reads 4 bytes from the stream, and (conceptually) concatenates
them according to the current byte order, converts the result
to a long, masks it with |
| public int | readUnsignedShort()
Implements javax. Reads two bytes from the stream, and (conceptually)
concatenates them according to the current byte order, converts
the resulting value to an |
| public String | readUTF()
Implements javax. Reads in a string that has been encoded using a modified UTF-8 format. |
| public void | reset()
Implements javax. Resets the current stream byte and bit positions from the stack of marked positions. |
| public void | seek(long pos)
Implements javax. Sets the current stream position to the desired location. |
| public void | setBitOffset(int bitOffset)
Implements javax. Sets the bit offset to an integer between 0 and 7, inclusive. |
| public void | setByteOrder(ByteOrder byteOrder)
Implements javax. Sets the desired byte order for future reads of data values from this stream. |
| public int | Returns: anint representing the number of bytes
skipped.the number of bytes to seek forward. n)Implements javax. Advances the current stream position by calling
|
| public long | Returns: along representing the number of bytes
skipped.the number of bytes to seek forward. n)Implements javax. Advances the current stream position by calling
|
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void |
| bitOffset | back to summary |
|---|---|
| protected int bitOffset The current bit offset within the stream. Subclasses are responsible for keeping this value current from any method they override that alters the bit offset. | |
| BYTE_BUF_LENGTH | back to summary |
|---|---|
| private static final int BYTE_BUF_LENGTH | |
| byteBuf | back to summary |
|---|---|
| pack-priv byte[] byteBuf Byte buffer used for readFully(type[], int, int). Note that this array is also used for bulk reads in readShort(), readInt(), etc, so it should be large enough to hold a primitive value (i.e. >= 8 bytes). Also note that this array is package protected, so that it can be used by ImageOutputStreamImpl in a similar manner. | |
| byteOrder | back to summary |
|---|---|
| protected ByteOrder byteOrder The byte order of the stream as an instance of the enumeration
class | |
| flushedPos | back to summary |
|---|---|
| protected long flushedPos The position prior to which data may be discarded. Seeking
to a smaller position is not allowed. | |
| isClosed | back to summary |
|---|---|
| private boolean isClosed | |
| markBitStack | back to summary |
|---|---|
| private final Stack<Integer> markBitStack | |
| markByteStack | back to summary |
|---|---|
| private final Stack<Long> markByteStack | |
| streamPos | back to summary |
|---|---|
| protected long streamPos The current read position within the stream. Subclasses are responsible for keeping this value current from any method they override that alters the read position. | |
| ImageInputStreamImpl | back to summary |
|---|---|
| public ImageInputStreamImpl() Constructs an | |
| checkClosed | back to summary |
|---|---|
| protected final void checkClosed() throws IOException Throws an
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Implements javax. Doc from javax. Closes the stream. Attempts to access a stream that has been
closed may result in
| |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Implements javax. Doc from javax. Discards the initial position of the stream prior to the current
stream position. Equivalent to
| |
| flushBefore | back to summary |
|---|---|
| public void flushBefore(long pos) throws IOException Implements javax. Doc from javax. Discards the initial portion of the stream prior to the
indicated position. Attempting to seek to an offset within the
flushed portion of the stream will result in an
Calling
| |
| getBitOffset | back to summary |
|---|---|
| public int getBitOffset() throws IOException Implements javax. Doc from javax. Returns the current bit offset, as an integer between 0 and 7,
inclusive. The bit offset is updated implicitly by calls to
the The bit offset is set to 0 when a stream is first
opened, and is reset to 0 by calls to
| |
| getByteOrder | back to summary |
|---|---|
| public ByteOrder getByteOrder() Implements javax. Doc from javax. Returns the byte order with which data values will be read from
this stream as an instance of the
| |
| getFlushedPosition | back to summary |
|---|---|
| public long getFlushedPosition() Implements javax. Doc from javax. Returns the earliest position in the stream to which seeking
may be performed. The returned value will be the maximum of
all values passed into previous calls to
| |
| getStreamPosition | back to summary |
|---|---|
| public long getStreamPosition() throws IOException Implements javax. Doc from javax. Returns the current byte position of the stream. The next read will take place starting at this offset.
| |
| isCached | back to summary |
|---|---|
| public boolean isCached() Implements javax. Default implementation returns false. Subclasses should override this if they cache data. | |
| isCachedFile | back to summary |
|---|---|
| public boolean isCachedFile() Implements javax. Default implementation returns false. Subclasses should override this if they cache data in a temporary file. | |
| isCachedMemory | back to summary |
|---|---|
| public boolean isCachedMemory() Implements javax. Default implementation returns false. Subclasses should override this if they cache data in main memory. | |
| length | back to summary |
|---|---|
| public long length() Implements javax. Returns
| |
| mark | back to summary |
|---|---|
| public void mark() Implements javax. Pushes the current stream position onto a stack of marked positions. | |
| read | back to summary |
|---|---|
| public abstract int read() throws IOException Redeclares javax. Reads a single byte from the stream and returns it as an
Subclasses must provide an implementation for this method. The subclass implementation should update the stream position before exiting. The bit offset within the stream must be reset to zero before the read occurs.
| |
| read | back to summary |
|---|---|
| public int read(byte[] b) throws IOException Implements javax. A convenience method that calls The bit offset within the stream is reset to zero before the read occurs.
| |
| read | back to summary |
|---|---|
| public abstract int read(byte[] b, int off, int len) throws IOException Redeclares javax. Reads up to The bit offset within the stream must be reset to zero before the read occurs. Subclasses must provide an implementation for this method. The subclass implementation should update the stream position before exiting.
| |
| readBit | back to summary |
|---|---|
| public int readBit() throws IOException Implements javax. Doc from javax. Reads a single bit from the stream and returns it as an
| |
| readBits | back to summary |
|---|---|
| public long readBits(int numBits) throws IOException Implements javax. Doc from javax. Reads a bitstring from the stream and returns it as a
The byte order of the stream has no effect on this method. The return value of this method is constructed as though the bits were read one at a time, and shifted into the right side of the return value, as shown by the following pseudo-code:
Note that the result of readBits(32) may thus not
be equal to that of readInt() if a reverse network
byte order is being used (i.e., getByteOrder() == false).
If the end of the stream is encountered before all the bits
have been read, a
| |
| readBoolean | back to summary |
|---|---|
| public boolean readBoolean() throws IOException Implements javax. Doc from javax. Reads a byte from the stream and returns a The bit offset within the stream is reset to zero before the read occurs.
| |
| readByte | back to summary |
|---|---|
| public byte readByte() throws IOException Implements javax. Doc from javax. Reads a byte from the stream and returns it as a
The bit offset within the stream is reset to zero before the read occurs.
| |
| readBytes | back to summary |
|---|---|
| public void readBytes(IIOByteBuffer buf, int len) throws IOException Implements javax. Doc from javax. Reads up to The bit offset within the stream is reset to zero before the read occurs.
| |
| readChar | back to summary |
|---|---|
| public char readChar() throws IOException Implements javax. Doc from javax. Equivalent to The bit offset within the stream is reset to zero before the read occurs.
| |
| readDouble | back to summary |
|---|---|
| public double readDouble() throws IOException Implements javax. Doc from javax. Reads 8 bytes from the stream, and (conceptually) concatenates
them according to the current byte order and returns the result
as a The bit offset within the stream is reset to zero before the read occurs.
| |
| readFloat | back to summary |
|---|---|
| public float readFloat() throws IOException Implements javax. Doc from javax. Reads 4 bytes from the stream, and (conceptually) concatenates
them according to the current byte order and returns the result
as a The bit offset within the stream is reset to zero before the read occurs.
| |
| readFully | back to summary |
|---|---|
| public void readFully(byte[] b, int off, int len) throws IOException Implements javax. Doc from javax. Reads The bit offset within the stream is reset to zero before the read occurs.
| |
| readFully | back to summary |
|---|---|
| public void readFully(byte[] b) throws IOException Implements javax. Doc from javax. Reads The bit offset within the stream is reset to zero before the read occurs.
| |
| readFully | back to summary |
|---|---|
| public void readFully(short[] s, int off, int len) throws IOException Implements javax. Doc from javax. Reads The bit offset within the stream is reset to zero before the read occurs.
| |
| readFully | back to summary |
|---|---|
| public void readFully(char[] c, int off, int len) throws IOException Implements javax. Doc from javax. Reads The bit offset within the stream is reset to zero before the read occurs.
| |
| readFully | back to summary |
|---|---|
| public void readFully(int[] i, int off, int len) throws IOException Implements javax. Doc from javax. Reads The bit offset within the stream is reset to zero before the read occurs.
| |
| readFully | back to summary |
|---|---|
| public void readFully(long[] l, int off, int len) throws IOException Implements javax. Doc from javax. Reads The bit offset within the stream is reset to zero before the read occurs.
| |
| readFully | back to summary |
|---|---|
| public void readFully(float[] f, int off, int len) throws IOException Implements javax. Doc from javax. Reads The bit offset within the stream is reset to zero before the read occurs.
| |
| readFully | back to summary |
|---|---|
| public void readFully(double[] d, int off, int len) throws IOException Implements javax. Doc from javax. Reads The bit offset within the stream is reset to zero before the read occurs.
| |
| readInt | back to summary |
|---|---|
| public int readInt() throws IOException Implements javax. Doc from javax. Reads 4 bytes from the stream, and (conceptually) concatenates
them according to the current byte order and returns the result
as an The bit offset within the stream is ignored and treated as though it were zero.
| |
| readLine | back to summary |
|---|---|
| public String readLine() throws IOException Implements javax. Doc from javax. Reads the next line of text from the input stream. It reads
successive bytes, converting each byte separately into a
character, until it encounters a line terminator or end of
file; the characters read are then returned as a
If end of file is encountered before even one byte can be
read, then The bit offset within the stream is reset to zero before the read occurs.
| |
| readLong | back to summary |
|---|---|
| public long readLong() throws IOException Implements javax. Doc from javax. Reads 8 bytes from the stream, and (conceptually) concatenates
them according to the current byte order and returns the result
as a The bit offset within the stream is reset to zero before the read occurs.
| |
| readShort | back to summary |
|---|---|
| public short readShort() throws IOException Implements javax. Doc from javax. Reads two bytes from the stream, and (conceptually)
concatenates them according to the current byte order, and
returns the result as a The bit offset within the stream is reset to zero before the read occurs.
| |
| readUnsignedByte | back to summary |
|---|---|
| public int readUnsignedByte() throws IOException Implements javax. Doc from javax. Reads a byte from the stream, and (conceptually) converts it to
an int, masks it with Thus, byte values between The bit offset within the stream is reset to zero before the read occurs.
| |
| readUnsignedInt | back to summary |
|---|---|
| public long readUnsignedInt() throws IOException Implements javax. Doc from javax. Reads 4 bytes from the stream, and (conceptually) concatenates
them according to the current byte order, converts the result
to a long, masks it with The bit offset within the stream is reset to zero before the read occurs.
| |
| readUnsignedShort | back to summary |
|---|---|
| public int readUnsignedShort() throws IOException Implements javax. Doc from javax. Reads two bytes from the stream, and (conceptually)
concatenates them according to the current byte order, converts
the resulting value to an The bit offset within the stream is reset to zero before the read occurs.
| |
| readUTF | back to summary |
|---|---|
| public String readUTF() throws IOException Implements javax. Doc from javax. Reads in a string that has been encoded using a
modified UTF-8
format. The general contract of First, two bytes are read and used to construct an unsigned
16-bit integer in the manner of the
If the first byte of a group matches the bit pattern
If the first byte of a group matches the bit pattern
If the first byte of a group matches the bit pattern
1110xxxx, then the group consists of that byte
a and two more bytes b and
c. If there is no byte c (because
byte a was one of the last two of the bytes to be
read), or either byte b or byte c
does not match the bit pattern 10xxxxxx, then a
UTFDataFormatException is thrown. Otherwise, the
group is converted to the character:
If the first byte of a group matches the pattern
1111xxxx or the pattern 10xxxxxx,
then a UTFDataFormatException is thrown.
If end of file is encountered at any time during this
entire process, then a After every group has been converted to a character by this
process, the characters are gathered, in the same order in
which their corresponding groups were read from the input
stream, to form a The current byte order setting is ignored. The bit offset within the stream is reset to zero before the read occurs. Note This method should not be used in the implementation of image formats that use standard UTF-8, because the modified UTF-8 used here is incompatible with standard UTF-8.
| |
| reset | back to summary |
|---|---|
| public void reset() throws IOException Implements javax. Resets the current stream byte and bit positions from the stack of marked positions. An
| |
| seek | back to summary |
|---|---|
| public void seek(long pos) throws IOException Implements javax. Doc from javax. Sets the current stream position to the desired location. The next read will occur at this location. The bit offset is set to 0. An It is legal to seek past the end of the file;
a
| |
| setBitOffset | back to summary |
|---|---|
| public void setBitOffset(int bitOffset) throws IOException Implements javax. Doc from javax. Sets the bit offset to an integer between 0 and 7, inclusive.
The byte offset within the stream, as returned by
| |
| setByteOrder | back to summary |
|---|---|
| public void setByteOrder(ByteOrder byteOrder) Implements javax. Doc from javax. Sets the desired byte order for future reads of data values from this stream. For example, the sequence of bytes '0x01 0x02 0x03 0x04' if read as a 4-byte integer would have the value '0x01020304' using network byte order and the value '0x04030201' under the reverse byte order. The enumeration class The byte order has no effect on the results returned from
the | |
| skipBytes | back to summary |
|---|---|
| public int skipBytes(int n) throws IOException Implements javax. Advances the current stream position by calling
The bit offset is reset to zero.
| |
| skipBytes | back to summary |
|---|---|
| public long skipBytes(long n) throws IOException Implements javax. Advances the current stream position by calling
The bit offset is reset to zero.
| |
| toChars | back to summary |
|---|---|
| private void toChars(byte[] b, char[] c, int off, int len) | |
| toDoubles | back to summary |
|---|---|
| private void toDoubles(byte[] b, double[] d, int off, int len) | |
| toFloats | back to summary |
|---|---|
| private void toFloats(byte[] b, float[] f, int off, int len) | |
| toInts | back to summary |
|---|---|
| private void toInts(byte[] b, int[] i, int off, int len) | |
| toLongs | back to summary |
|---|---|
| private void toLongs(byte[] b, long[] l, int off, int len) | |
| toShorts | back to summary |
|---|---|
| private void toShorts(byte[] b, short[] s, int off, int len) | |