. A memory buffer is
used to cache at least the data between the discard position and
the current read position.
| Method from javax.imageio.stream.MemoryCacheImageInputStream Detail: |
public void close() throws IOException {
super.close();
disposerRecord.dispose(); // this resets the MemoryCache
stream = null;
cache = null;
}
Closes this MemoryCacheImageInputStream, freeing
the cache. The source InputStream is not closed. |
protected void finalize() throws Throwable {
// Empty finalizer: for performance reasons we instead use the
// Disposer mechanism for ensuring that the underlying
// MemoryCache is reset prior to garbage collection
}
|
public void flushBefore(long pos) throws IOException {
super.flushBefore(pos); // this will call checkClosed() for us
cache.disposeBefore(pos);
}
|
public boolean isCached() {
return true;
}
Returns true since this
ImageInputStream caches data in order to allow
seeking backwards. |
public boolean isCachedFile() {
return false;
}
Returns false since this
ImageInputStream does not maintain a file cache. |
public boolean isCachedMemory() {
return true;
}
Returns true since this
ImageInputStream maintains a main memory cache. |
public int read() throws IOException {
checkClosed();
bitOffset = 0;
long pos = cache.loadFromStream(stream, streamPos+1);
if (pos >= streamPos+1) {
return cache.read(streamPos++);
} else {
return -1;
}
}
|
public int read(byte[] b,
int off,
int len) throws IOException {
checkClosed();
if (b == null) {
throw new NullPointerException("b == null!");
}
if (off < 0 || len < 0 || off + len > b.length || off + len < 0) {
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off+len > b.length || off+len < 0!");
}
bitOffset = 0;
if (len == 0) {
return 0;
}
long pos = cache.loadFromStream(stream, streamPos+len);
len = (int)(pos - streamPos); // In case stream ended early
if (len > 0) {
cache.read(b, off, len, streamPos);
streamPos += len;
return len;
} else {
return -1;
}
}
|