FileCacheImageInputStream (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")
public class FileCacheImageInputStream extends ImageInputStreamImpl
An implementation of ImageInputStream
that gets its input from a regular InputStream
. A file is used to cache previously read data.
Field Summary
Constructor Summary
Constructors
Constructor | Description |
---|---|
FileCacheImageInputStream(InputStream stream,File cacheDir) | Constructs a FileCacheImageInputStream that will read from a given InputStream. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void | close() | Closes this FileCacheImageInputStream, closing and removing the cache file. |
protected void | finalize() | Deprecated. |
boolean | isCached() | Returns true since thisImageInputStream caches data in order to allow seeking backwards. |
boolean | isCachedFile() | Returns true since thisImageInputStream maintains a file cache. |
boolean | isCachedMemory() | Returns false since thisImageInputStream does not maintain a main memory cache. |
Methods declared in interface javax.imageio.stream.ImageInputStream
[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)
Constructor Details
FileCacheImageInputStream
Constructs a
FileCacheImageInputStream
that will read from a givenInputStream
.
A temporary file is used as a cache. IfcacheDir
is non-null
and is a directory, the file will be created there. If it isnull
, the system-dependent default temporary-file directory will be used (see the documentation forFile.createTempFile
for details).
Parameters:
stream
- anInputStream
to read from.
cacheDir
- aFile
indicating where the cache file should be created, ornull
to use the system directory.
Throws:
[IllegalArgumentException](../../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifstream
isnull
.
[IllegalArgumentException](../../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- ifcacheDir
is non-null
but is not a directory.
[IOException](../../../../java.base/java/io/IOException.html "class in java.io")
- if a cache file cannot be created.Method Details
isCached
public boolean isCached()
Returnstrue
since thisImageInputStream
caches data in order to allow seeking backwards.
Specified by:
[isCached](ImageInputStream.html#isCached%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Overrides:
[isCached](ImageInputStreamImpl.html#isCached%28%29)
in class[ImageInputStreamImpl](ImageInputStreamImpl.html "class in javax.imageio.stream")
Returns:
true
.
See Also:
isCachedMemory(), isCachedFile()isCachedFile
public boolean isCachedFile()
Returnstrue
since thisImageInputStream
maintains a file cache.
Specified by:
[isCachedFile](ImageInputStream.html#isCachedFile%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Overrides:
[isCachedFile](ImageInputStreamImpl.html#isCachedFile%28%29)
in class[ImageInputStreamImpl](ImageInputStreamImpl.html "class in javax.imageio.stream")
Returns:
true
.
See Also:
isCached(), isCachedMemory()isCachedMemory
public boolean isCachedMemory()
Returnsfalse
since thisImageInputStream
does not maintain a main memory cache.
Specified by:
[isCachedMemory](ImageInputStream.html#isCachedMemory%28%29)
in interface[ImageInputStream](ImageInputStream.html "interface in javax.imageio.stream")
Overrides:
[isCachedMemory](ImageInputStreamImpl.html#isCachedMemory%28%29)
in class[ImageInputStreamImpl](ImageInputStreamImpl.html "class in javax.imageio.stream")
Returns:
false
.
See Also:
isCached(), isCachedFile()close
Closes this
FileCacheImageInputStream
, closing and removing the cache file. The sourceInputStream
is not closed.
Throws:
[IOException](../../../../java.base/java/io/IOException.html "class in java.io")
- if an error occurs.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](ImageInputStreamImpl.html#finalize%28%29)
in class[ImageInputStreamImpl](ImageInputStreamImpl.html "class in javax.imageio.stream")
Throws:
[Throwable](../../../../java.base/java/lang/Throwable.html "class in java.lang")
- if an error occurs during superclass finalization.
See Also:
WeakReference, PhantomReference