- java.lang.Object
- 
- javax.imageio.stream.ImageInputStreamImpl
 
- 
- All Implemented Interfaces:
- Closeable,- DataInput,- AutoCloseable,- ImageInputStream
 - Direct Known Subclasses:
- FileCacheImageInputStream,- FileImageInputStream,- ImageOutputStreamImpl,- MemoryCacheImageInputStream
 
 public abstract class ImageInputStreamImpl extends Object implements ImageInputStream An abstract class implementing theImageInputStreaminterface. 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. 
- 
- 
Field SummaryFields Modifier and Type Field Description protected intbitOffsetThe current bit offset within the stream.protected ByteOrderbyteOrderThe byte order of the stream as an instance of the enumeration classjava.nio.ByteOrder, whereByteOrder.BIG_ENDIANindicates network byte order andByteOrder.LITTLE_ENDIANindicates the reverse order.protected longflushedPosThe position prior to which data may be discarded.protected longstreamPosThe current read position within the stream.
 - 
Constructor SummaryConstructors Constructor Description ImageInputStreamImpl()Constructs anImageInputStreamImpl.
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidcheckClosed()Throws anIOExceptionif the stream has been closed.protected voidfinalize()Deprecated.Thefinalizemethod has been deprecated.booleanisCached()Default implementation returns false.booleanisCachedFile()Default implementation returns false.booleanisCachedMemory()Default implementation returns false.longlength()Returns-1Lto indicate that the stream has unknown length.voidmark()Pushes the current stream position onto a stack of marked positions.abstract intread()Reads a single byte from the stream and returns it as anintbetween 0 and 255.intread(byte[] b)A convenience method that callsread(b, 0, b.length).abstract intread(byte[] b, int off, int len)Reads up tolenbytes from the stream, and stores them intobstarting at indexoff.voidreset()Resets the current stream byte and bit positions from the stack of marked positions.intskipBytes(int n)Advances the current stream position by callingseek(getStreamPosition() + n).longskipBytes(long n)Advances the current stream position by callingseek(getStreamPosition() + n).- 
Methods declared in class java.lang.Objectclone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods declared in interface javax.imageio.stream.ImageInputStreamclose, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, readBit, readBits, readBoolean, readByte, readBytes, readChar, readDouble, readFloat, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, readUTF, seek, setBitOffset, setByteOrder
 
- 
 
- 
- 
- 
Field Detail- 
byteOrderprotected ByteOrder byteOrder The byte order of the stream as an instance of the enumeration classjava.nio.ByteOrder, whereByteOrder.BIG_ENDIANindicates network byte order andByteOrder.LITTLE_ENDIANindicates the reverse order. By default, the value isByteOrder.BIG_ENDIAN.
 - 
streamPosprotected 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.
 - 
bitOffsetprotected 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.
 - 
flushedPosprotected long flushedPos The position prior to which data may be discarded. Seeking to a smaller position is not allowed.flushedPoswill always be >= 0.
 
- 
 - 
Method Detail- 
checkClosedprotected final void checkClosed() throws IOExceptionThrows anIOExceptionif the stream has been closed. Subclasses may call this method from any of their methods that require the stream not to be closed.- Throws:
- IOException- if the stream is closed.
 
 - 
readpublic abstract int read() throws IOExceptionReads a single byte from the stream and returns it as anintbetween 0 and 255. If EOF is reached,-1is returned.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. - Specified by:
- readin interface- ImageInputStream
- Returns:
- the value of the next byte in the stream, or -1if EOF is reached.
- Throws:
- IOException- if the stream has been closed.
 
 - 
readpublic int read(byte[] b) throws IOExceptionA convenience method that callsread(b, 0, b.length).The bit offset within the stream is reset to zero before the read occurs. - Specified by:
- readin interface- ImageInputStream
- Parameters:
- b- an array of bytes to be written to.
- Returns:
- the number of bytes actually read, or -1to indicate EOF.
- Throws:
- NullPointerException- if- bis- null.
- IOException- if an I/O error occurs.
 
 - 
readpublic abstract int read(byte[] b, int off, int len) throws IOExceptionReads up tolenbytes from the stream, and stores them intobstarting at indexoff. If no bytes can be read because the end of the stream has been reached,-1is returned.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. - Specified by:
- readin interface- ImageInputStream
- Parameters:
- b- an array of bytes to be written to.
- off- the starting position within- bto write to.
- len- the maximum number of bytes to read.
- Returns:
- the number of bytes actually read, or -1to indicate EOF.
- Throws:
- IndexOutOfBoundsException- if- offis negative,- lenis negative, or- off + lenis greater than- b.length.
- NullPointerException- if- bis- null.
- IOException- if an I/O error occurs.
 
 - 
lengthpublic long length() Returns-1Lto indicate that the stream has unknown length. Subclasses must override this method to provide actual length information.- Specified by:
- lengthin interface- ImageInputStream
- Returns:
- -1L to indicate unknown length.
 
 - 
skipBytespublic int skipBytes(int n) throws IOExceptionAdvances the current stream position by callingseek(getStreamPosition() + n).The bit offset is reset to zero. - Specified by:
- skipBytesin interface- DataInput
- Specified by:
- skipBytesin interface- ImageInputStream
- Parameters:
- n- the number of bytes to seek forward.
- Returns:
- an intrepresenting the number of bytes skipped.
- Throws:
- IOException- if- getStreamPositionthrows an- IOExceptionwhen computing either the starting or ending position.
 
 - 
skipBytespublic long skipBytes(long n) throws IOExceptionAdvances the current stream position by callingseek(getStreamPosition() + n).The bit offset is reset to zero. - Specified by:
- skipBytesin interface- ImageInputStream
- Parameters:
- n- the number of bytes to seek forward.
- Returns:
- a longrepresenting the number of bytes skipped.
- Throws:
- IOException- if- getStreamPositionthrows an- IOExceptionwhen computing either the starting or ending position.
 
 - 
markpublic void mark() Pushes the current stream position onto a stack of marked positions.- Specified by:
- markin interface- ImageInputStream
 
 - 
resetpublic void reset() throws IOExceptionResets the current stream byte and bit positions from the stack of marked positions.An IOExceptionwill be thrown if the previous marked position lies in the discarded portion of the stream.- Specified by:
- resetin interface- ImageInputStream
- Throws:
- IOException- if an I/O error occurs.
 
 - 
isCachedpublic boolean isCached() Default implementation returns false. Subclasses should override this if they cache data.- Specified by:
- isCachedin interface- ImageInputStream
- Returns:
- trueif this- ImageInputStreamcaches data.
- See Also:
- ImageInputStream.isCachedMemory(),- ImageInputStream.isCachedFile()
 
 - 
isCachedMemorypublic boolean isCachedMemory() Default implementation returns false. Subclasses should override this if they cache data in main memory.- Specified by:
- isCachedMemoryin interface- ImageInputStream
- Returns:
- trueif this- ImageInputStreamcaches data in main memory.
- See Also:
- ImageInputStream.isCached(),- ImageInputStream.isCachedFile()
 
 - 
isCachedFilepublic boolean isCachedFile() Default implementation returns false. Subclasses should override this if they cache data in a temporary file.- Specified by:
- isCachedFilein interface- ImageInputStream
- Returns:
- trueif this- ImageInputStreamcaches data in a temporary file.
- See Also:
- ImageInputStream.isCached(),- ImageInputStream.isCachedMemory()
 
 - 
finalize@Deprecated(since="9") protected void finalize() throws Throwable Deprecated.Thefinalizemethod has been deprecated. Subclasses that overridefinalizein order to perform cleanup should be modified to use alternative cleanup mechanisms and to remove the overridingfinalizemethod. When overriding thefinalizemethod, its implementation must explicitly ensure thatsuper.finalize()is invoked as described inObject.finalize(). See the specification forObject.finalize()for further information about migration options.Finalizes this object prior to garbage collection. Theclosemethod is called to close any open input source. This method should not be called from application code.- Overrides:
- finalizein class- Object
- Throws:
- Throwable- if an error occurs during superclass finalization.
- See Also:
- WeakReference,- PhantomReference
 
 
- 
 
-