ImageInputStreamImpl (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[Closeable](../../../../java.base/java/io/Closeable.html "interface in java.io")
, [DataInput](../../../../java.base/java/io/DataInput.html "interface in java.io")
, [AutoCloseable](../../../../java.base/java/lang/AutoCloseable.html "interface in java.lang")
, [ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Direct Known Subclasses:
[FileCacheImageInputStream](FileCacheImageInputStream.html "class in javax.imageio.stream")
, [FileImageInputStream](FileImageInputStream.html "class in javax.imageio.stream")
, [ImageOutputStreamImpl](ImageOutputStreamImpl.html "class in javax.imageio.stream")
, [MemoryCacheImageInputStream](MemoryCacheImageInputStream.html "class in javax.imageio.stream")
public abstract class ImageInputStreamImpl extends Object implements ImageInputStream
An abstract class implementing the 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.
Field Summary
Fields
Modifier and Type | Field | Description |
---|---|---|
protected int | bitOffset | The current bit offset within the stream. |
protected ByteOrder | byteOrder | The byte order of the stream as an instance of the enumeration class java.nio.ByteOrder, whereByteOrder.BIG_ENDIAN indicates network byte order and ByteOrder.LITTLE_ENDIAN indicates the reverse order. |
protected long | flushedPos | The position prior to which data may be discarded. |
protected long | streamPos | The current read position within the stream. |
Constructor Summary
Constructors
Constructor | Description |
---|---|
ImageInputStreamImpl() | Constructs an ImageInputStreamImpl. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
protected void | checkClosed() | Throws an IOException if the stream has been closed. |
protected void | finalize() | Deprecated. |
boolean | isCached() | Default implementation returns false. |
boolean | isCachedFile() | Default implementation returns false. |
boolean | isCachedMemory() | Default implementation returns false. |
long | length() | Returns -1L to indicate that the stream has unknown length. |
void | mark() | Pushes the current stream position onto a stack of marked positions. |
abstract int | read() | Reads a single byte from the stream and returns it as anint between 0 and 255. |
int | read(byte[] b) | A convenience method that calls read(b, 0, b.length). |
abstract int | read(byte[] b, int off, int len) | Reads up to len bytes from the stream, and stores them into b starting at index off. |
void | reset() | Resets the current stream byte and bit positions from the stack of marked positions. |
int | skipBytes(int n) | Advances the current stream position by callingseek(getStreamPosition() + n). |
long | skipBytes(long n) | Advances the current stream position by callingseek(getStreamPosition() + n). |
Methods declared in interface javax.imageio.stream.ImageInputStream
[close](ImageInputStream.html#close%28%29), [flush](ImageInputStream.html#flush%28%29), [flushBefore](ImageInputStream.html#flushBefore%28long%29), [getBitOffset](ImageInputStream.html#getBitOffset%28%29), [getByteOrder](ImageInputStream.html#getByteOrder%28%29), [getFlushedPosition](ImageInputStream.html#getFlushedPosition%28%29), [getStreamPosition](ImageInputStream.html#getStreamPosition%28%29), [readBit](ImageInputStream.html#readBit%28%29), [readBits](ImageInputStream.html#readBits%28int%29), [readBoolean](ImageInputStream.html#readBoolean%28%29), [readByte](ImageInputStream.html#readByte%28%29), [readBytes](ImageInputStream.html#readBytes%28javax.imageio.stream.IIOByteBuffer,int%29), [readChar](ImageInputStream.html#readChar%28%29), [readDouble](ImageInputStream.html#readDouble%28%29), [readFloat](ImageInputStream.html#readFloat%28%29), [readFully](ImageInputStream.html#readFully%28byte%5B%5D%29), [readFully](ImageInputStream.html#readFully%28byte%5B%5D,int,int%29), [readFully](ImageInputStream.html#readFully%28char%5B%5D,int,int%29), [readFully](ImageInputStream.html#readFully%28double%5B%5D,int,int%29), [readFully](ImageInputStream.html#readFully%28float%5B%5D,int,int%29), [readFully](ImageInputStream.html#readFully%28int%5B%5D,int,int%29), [readFully](ImageInputStream.html#readFully%28long%5B%5D,int,int%29), [readFully](ImageInputStream.html#readFully%28short%5B%5D,int,int%29), [readInt](ImageInputStream.html#readInt%28%29), [readLine](ImageInputStream.html#readLine%28%29), [readLong](ImageInputStream.html#readLong%28%29), [readShort](ImageInputStream.html#readShort%28%29), [readUnsignedByte](ImageInputStream.html#readUnsignedByte%28%29), [readUnsignedInt](ImageInputStream.html#readUnsignedInt%28%29), [readUnsignedShort](ImageInputStream.html#readUnsignedShort%28%29), [readUTF](ImageInputStream.html#readUTF%28%29), [seek](ImageInputStream.html#seek%28long%29), [setBitOffset](ImageInputStream.html#setBitOffset%28int%29), [setByteOrder](ImageInputStream.html#setByteOrder%28java.nio.ByteOrder%29)
Field Details
byteOrder
The byte order of the stream as an instance of the enumeration class
java.nio.ByteOrder
, whereByteOrder.BIG_ENDIAN
indicates network byte order andByteOrder.LITTLE_ENDIAN
indicates the reverse order. By default, the value isByteOrder.BIG_ENDIAN
.streamPos
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.bitOffset
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.flushedPos
protected long flushedPos
The position prior to which data may be discarded. Seeking to a smaller position is not allowed.flushedPos
will always be >= 0.Constructor Details
ImageInputStreamImpl
public ImageInputStreamImpl()
Constructs anImageInputStreamImpl
.Method Details
checkClosed
protected final void checkClosed() throws IOException
Throws anIOException
if 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](../../../../java.base/java/io/IOException.html "class in java.io")
- if the stream is closed.read
public abstract int read() throws IOException
Reads a single byte from the stream and returns it as anint
between 0 and 255. If EOF is reached,-1
is 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:
[read](ImageInputStream.html#read%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Returns:
the value of the next byte in the stream, or-1
if EOF is reached.
Throws:
[IOException](../../../../java.base/java/io/IOException.html "class in java.io")
- if the stream has been closed.read
public int read(byte[] b) throws IOException
A convenience method that callsread(b, 0, b.length)
.
The bit offset within the stream is reset to zero before the read occurs.
Specified by:
[read](ImageInputStream.html#read%28byte%5B%5D%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Parameters:
b
- an array of bytes to be written to.
Returns:
the number of bytes actually read, or-1
to indicate EOF.
Throws:
[NullPointerException](../../../../java.base/java/lang/NullPointerException.html "class in java.lang")
- ifb
isnull
.
[IOException](../../../../java.base/java/io/IOException.html "class in java.io")
- if an I/O error occurs.read
public abstract int read(byte[] b, int off, int len) throws IOException
Reads up tolen
bytes from the stream, and stores them intob
starting at indexoff
. If no bytes can be read because the end of the stream has been reached,-1
is 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:
[read](ImageInputStream.html#read%28byte%5B%5D,int,int%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Parameters:
b
- an array of bytes to be written to.
off
- the starting position withinb
to write to.
len
- the maximum number of bytes to read.
Returns:
the number of bytes actually read, or-1
to indicate EOF.
Throws:
[IndexOutOfBoundsException](../../../../java.base/java/lang/IndexOutOfBoundsException.html "class in java.lang")
- ifoff
is negative,len
is negative, oroff + len
is greater thanb.length
.
[NullPointerException](../../../../java.base/java/lang/NullPointerException.html "class in java.lang")
- ifb
isnull
.
[IOException](../../../../java.base/java/io/IOException.html "class in java.io")
- if an I/O error occurs.length
public long length()
Returns-1L
to indicate that the stream has unknown length. Subclasses must override this method to provide actual length information.
Specified by:
[length](ImageInputStream.html#length%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Returns:
-1L to indicate unknown length.skipBytes
public int skipBytes(int n) throws IOException
Advances the current stream position by callingseek(getStreamPosition() + n)
.
The bit offset is reset to zero.
Specified by:
[skipBytes](../../../../java.base/java/io/DataInput.html#skipBytes%28int%29)
in interface[DataInput](../../../../java.base/java/io/DataInput.html "interface in java.io")
Specified by:
[skipBytes](ImageInputStream.html#skipBytes%28int%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Parameters:
n
- the number of bytes to seek forward.
Returns:
anint
representing the number of bytes skipped.
Throws:
[IOException](../../../../java.base/java/io/IOException.html "class in java.io")
- ifgetStreamPosition
throws anIOException
when computing either the starting or ending position.skipBytes
public long skipBytes(long n) throws IOException
Advances the current stream position by callingseek(getStreamPosition() + n)
.
The bit offset is reset to zero.
Specified by:
[skipBytes](ImageInputStream.html#skipBytes%28long%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Parameters:
n
- the number of bytes to seek forward.
Returns:
along
representing the number of bytes skipped.
Throws:
[IOException](../../../../java.base/java/io/IOException.html "class in java.io")
- ifgetStreamPosition
throws anIOException
when computing either the starting or ending position.mark
public void mark()
Pushes the current stream position onto a stack of marked positions.
Specified by:
[mark](ImageInputStream.html#mark%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
reset
Resets the current stream byte and bit positions from the stack of marked positions.
AnIOException
will be thrown if the previous marked position lies in the discarded portion of the stream.
Specified by:
[reset](ImageInputStream.html#reset%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Throws:
[IOException](../../../../java.base/java/io/IOException.html "class in java.io")
- if an I/O error occurs.isCached
public boolean isCached()
Default implementation returns false. Subclasses should override this if they cache data.
Specified by:
[isCached](ImageInputStream.html#isCached%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Returns:
true
if thisImageInputStream
caches data.
See Also:
ImageInputStream.isCachedMemory(), ImageInputStream.isCachedFile()isCachedMemory
public boolean isCachedMemory()
Default implementation returns false. Subclasses should override this if they cache data in main memory.
Specified by:
[isCachedMemory](ImageInputStream.html#isCachedMemory%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Returns:
true
if thisImageInputStream
caches data in main memory.
See Also:
ImageInputStream.isCached(), ImageInputStream.isCachedFile()isCachedFile
public boolean isCachedFile()
Default implementation returns false. Subclasses should override this if they cache data in a temporary file.
Specified by:
[isCachedFile](ImageInputStream.html#isCachedFile%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Returns:
true
if thisImageInputStream
caches data in a temporary file.
See Also:
ImageInputStream.isCached(), ImageInputStream.isCachedMemory()finalize
Finalizes this object prior to garbage collection. The
close
method is called to close any open input source. This method should not be called from application code.
Overrides:
[finalize](../../../../java.base/java/lang/Object.html#finalize%28%29)
in class[Object](../../../../java.base/java/lang/Object.html "class in java.lang")
Throws:
[Throwable](../../../../java.base/java/lang/Throwable.html "class in java.lang")
- if an error occurs during superclass finalization.
See Also:
WeakReference, PhantomReference