Top Description Inners Fields Constructors Methods
javax.imageio.stream

public Class FileCacheImageInputStream

extends ImageInputStreamImpl
Class Inheritance
Imports
java.io.File, .InputStream, .IOException, .RandomAccessFile, java.nio.file.Files, com.sun.imageio.stream.StreamCloser, .StreamFinalizer, sun.java2d.Disposer, .DisposerRecord

An implementation of ImageInputStream that gets its input from a regular InputStream. A file is used to cache previously read data.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private byte[]
private static final int
private RandomAccessFile
private File
private final StreamCloser.CloseAction
closeAction

The CloseAction that closes the stream in the StreamCloser's shutdown hook

private final DisposerRecord
disposerRecord

The DisposerRecord that closes the underlying cache.

private final Object
disposerReferent

The referent to be registered with the Disposer.

private boolean
private long
private InputStream
Inherited from javax.imageio.stream.ImageInputStreamImpl:
bitOffsetbyteBufbyteOrderflushedPosstreamPos

Constructor Summary

AccessConstructor and Description
public
FileCacheImageInputStream(InputStream
an InputStream to read from.
stream
,
File
a File indicating where the cache file should be created, or null to use the system directory.
cacheDir
)

Constructs a FileCacheImageInputStream 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 FileCacheImageInputStream, closing and removing the cache file.

protected void
finalize()

Overrides javax.imageio.stream.ImageInputStreamImpl.finalize.

Deprecated for removal since 9. Finalization has been deprecated for removal. See java.lang.Object#finalize for background information and details about migration options.

Finalizes this object prior to garbage collection.

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:

true.
isCachedFile
()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedFile.

Implements javax.imageio.stream.ImageInputStream.isCachedFile.

Returns true since this ImageInputStream maintains a file cache.

public boolean

Returns:

false.
isCachedMemory
()

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedMemory.

Implements javax.imageio.stream.ImageInputStream.isCachedMemory.

Returns false since this ImageInputStream does not maintain 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[]
an array of bytes to be written to.
b
,
int
the starting position within b to write to.
off
,
int
the maximum number of bytes to read.
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.

private long
readUntil(long pos)

Ensures that at least pos bytes are cached, or the end of the source is reached.

Inherited from javax.imageio.stream.ImageInputStreamImpl:
checkClosedflushflushBeforegetBitOffsetgetByteOrdergetFlushedPositiongetStreamPositionlengthmarkreadreadBitreadBitsreadBooleanreadBytereadBytesreadCharreadDoublereadFloatreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadIntreadLinereadLongreadShortreadUnsignedBytereadUnsignedIntreadUnsignedShortreadUTFresetseeksetBitOffsetsetByteOrderskipBytesskipBytes

Field Detail

bufback to summary
private byte[] buf
BUFFER_LENGTHback to summary
private static final int BUFFER_LENGTH
cacheback to summary
private RandomAccessFile cache
cacheFileback to summary
private File cacheFile
closeActionback to summary
private final StreamCloser.CloseAction closeAction

The CloseAction that closes the stream in the StreamCloser's shutdown hook

disposerRecordback to summary
private final DisposerRecord disposerRecord

The DisposerRecord that closes the underlying cache.

disposerReferentback to summary
private final Object disposerReferent

The referent to be registered with the Disposer.

foundEOFback to summary
private boolean foundEOF
lengthback to summary
private long length
streamback to summary
private InputStream stream

Constructor Detail

FileCacheImageInputStreamback to summary
public FileCacheImageInputStream(InputStream stream, File cacheDir) throws IOException

Constructs a FileCacheImageInputStream that will read from a given InputStream.

A temporary file is used as a cache. If cacheDir is non-null and is a directory, the file will be created there. If it is null, the system-dependent default temporary-file directory will be used (see the documentation for File.createTempFile for details).

Parameters
stream:InputStream

an InputStream to read from.

cacheDir:File

a File indicating where the cache file should be created, or null to use the system directory.

Exceptions
IOException:
if a cache file cannot be created.
IllegalArgumentException:
  • if stream is null.
  • if cacheDir is non-null but is not a directory.

Method Detail

closeback to summary
public void close() throws IOException

Overrides javax.imageio.stream.ImageInputStreamImpl.close.

Implements javax.imageio.stream.ImageInputStream.close.

Closes this FileCacheImageInputStream, closing and removing the cache file. The source InputStream is not closed.

Exceptions
IOException:
if an error occurs.
finalizeback to summary
protected void finalize() throws Throwable

Overrides javax.imageio.stream.ImageInputStreamImpl.finalize.

Doc from javax.imageio.stream.ImageInputStreamImpl.finalize.

Deprecated

for removal since 9.

Finalization has been deprecated for removal. See java.lang.Object#finalize for background information and details about migration options.

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.

Annotations
@Deprecated
since:9
forRemoval:true
@SuppressWarnings:removal
Exceptions
Throwable:
if an error occurs during superclass finalization.
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 true since this ImageInputStream maintains a file cache.

Returns:boolean

true.

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

Overrides javax.imageio.stream.ImageInputStreamImpl.isCachedMemory.

Implements javax.imageio.stream.ImageInputStream.isCachedMemory.

Returns false since this ImageInputStream does not maintain a main memory cache.

Returns:boolean

false.

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.

Returns:int

the value of the next byte in the stream, or -1 if EOF is reached.

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.

Parameters
b:byte[]

an array of bytes to be written to.

off:int

the starting position within b to write to.

len:int

the maximum number of bytes to read.

Returns:int

the number of bytes actually read, or -1 to indicate EOF.

Exceptions
IOException:
if an I/O error occurs.
readUntilback to summary
private long readUntil(long pos) throws IOException

Ensures that at least pos bytes are cached, or the end of the source is reached. The return value is equal to the smaller of pos and the length of the source file.

Exceptions
IOException:
if an I/O error occurs while reading from the source file
javax.imageio.stream back to summary

private Class FileCacheImageInputStream.StreamDisposerRecord

extends Object
implements DisposerRecord
Class Inheritance
  • java.lang.Object
  • javax.imageio.stream.FileCacheImageInputStream.StreamDisposerRecord
All Implemented Interfaces
sun.java2d.DisposerRecord

Field Summary

Modifier and TypeField and Description
private RandomAccessFile
private File

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private RandomAccessFile cache
cacheFileback to summary
private File cacheFile

Constructor Detail

StreamDisposerRecordback to summary
public StreamDisposerRecord(File cacheFile, RandomAccessFile cache)

Method Detail

disposeback to summary
public synchronized void dispose()

Implements sun.java2d.DisposerRecord.dispose.