APIdia Launch Partner
Top Description Fields Constructors Methods
javax.imageio.stream

public Class MemoryCacheImageInputStream

extends ImageInputStreamImpl
Class Inheritance
Imports
java.io.InputStream, .IOException

An implementation of ImageInputStream that gets its input from a regular InputStream. A memory buffer is used to cache at least the data between the discard position and the current read position.

In general, it is preferable to use a FileCacheImageInputStream when reading from a regular InputStream. This class is provided for cases where it is not possible to create a writable temporary file.

Field Summary

Modifier and TypeField and Description
private MemoryCache
private InputStream
Inherited from javax.imageio.stream.ImageInputStreamImpl:
bitOffsetbyteBufbyteOrderflushedPosstreamPos

Constructor Summary

AccessConstructor and Description
public
MemoryCacheImageInputStream(InputStream
an InputStream to read from.
stream
)

Constructs a MemoryCacheImageInputStream that will read from a given InputStream.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides javax.imageio.stream.ImageInputStreamImpl.close.

Implements javax.imageio.stream.ImageInputStream.close.

Closes this MemoryCacheImageInputStream, freeing the cache.

public void
flushBefore(long pos)

Overrides javax.imageio.stream.ImageInputStreamImpl.flushBefore.

Implements javax.imageio.stream.ImageInputStream.flushBefore.

Discards the initial portion of the stream prior to the indicated position.

public boolean

Returns:

true.
isCached
()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCached.

Implements javax.imageio.stream.ImageInputStream.isCached.

Returns true since this ImageInputStream caches data in order to allow seeking backwards.

public boolean

Returns:

false.
isCachedFile
()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedFile.

Implements javax.imageio.stream.ImageInputStream.isCachedFile.

Returns false since this ImageInputStream does not maintain a file cache.

public boolean

Returns:

true.
isCachedMemory
()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedMemory.

Implements javax.imageio.stream.ImageInputStream.isCachedMemory.

Returns true since this ImageInputStream maintains a main memory cache.

public int
read()

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Reads a single byte from the stream and returns it as an int between 0 and 255.

public int
read(byte[] b, int off, int len)

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Reads up to len bytes from the stream, and stores them into b starting at index off.

Inherited from javax.imageio.stream.ImageInputStreamImpl:
checkClosedflushgetBitOffsetgetByteOrdergetFlushedPositiongetStreamPositionlengthmarkreadreadBitreadBitsreadBooleanreadBytereadBytesreadCharreadDoublereadFloatreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadIntreadLinereadLongreadShortreadUnsignedBytereadUnsignedIntreadUnsignedShortreadUTFresetseeksetBitOffsetsetByteOrderskipBytesskipBytes

Field Detail

cacheback to summary
private MemoryCache cache
streamback to summary
private InputStream stream

Constructor Detail

MemoryCacheImageInputStreamback to summary
public MemoryCacheImageInputStream(InputStream stream)

Constructs a MemoryCacheImageInputStream that will read from a given InputStream.

Parameters
stream:InputStream

an InputStream to read from.

Exceptions
IllegalArgumentException:
if stream is null.

Method Detail

closeback to summary
public void close() throws IOException

Overrides javax.imageio.stream.ImageInputStreamImpl.close.

Implements javax.imageio.stream.ImageInputStream.close.

Closes this MemoryCacheImageInputStream, freeing the cache. The source InputStream is not closed.

Exceptions
IOException:

Doc from javax.imageio.stream.ImageInputStream.close.

if an I/O error occurs.

flushBeforeback to summary
public void flushBefore(long pos) throws IOException

Overrides javax.imageio.stream.ImageInputStreamImpl.flushBefore.

Implements javax.imageio.stream.ImageInputStream.flushBefore.

Doc from javax.imageio.stream.ImageInputStream.flushBefore.

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 IndexOutOfBoundsException.

Calling flushBefore may allow classes implementing this interface to free up resources such as memory or disk space that are being used to store data from the stream.

Exceptions
IOException:
if an I/O error occurs.
isCachedback to summary
public boolean isCached()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCached.

Implements javax.imageio.stream.ImageInputStream.isCached.

Returns true since this ImageInputStream caches data in order to allow seeking backwards.

Returns:boolean

true.

See Also
isCachedMemory, isCachedFile
isCachedFileback to summary
public boolean isCachedFile()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedFile.

Implements javax.imageio.stream.ImageInputStream.isCachedFile.

Returns false since this ImageInputStream does not maintain a file cache.

Returns:boolean

false.

See Also
isCached, isCachedMemory
isCachedMemoryback to summary
public boolean isCachedMemory()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedMemory.

Implements javax.imageio.stream.ImageInputStream.isCachedMemory.

Returns true since this ImageInputStream maintains a main memory cache.

Returns:boolean

true.

See Also
isCached, isCachedFile
readback to summary
public int read() throws IOException

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Doc from javax.imageio.stream.ImageInputStreamImpl.read.

Reads a single byte from the stream and returns it as an int 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.

Exceptions
IOException:
if the stream has been closed.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Doc from javax.imageio.stream.ImageInputStreamImpl.read.

Reads up to len bytes from the stream, and stores them into b starting at index off. 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.

Exceptions
IOException:
if an I/O error occurs.