Methods Summary |
---|
public void | close()Closes this MemoryCacheImageInputStream , freeing
the cache. The source InputStream is not closed.
super.close();
disposerRecord.dispose(); // this resets the MemoryCache
stream = null;
cache = null;
|
protected void | finalize(){@inheritDoc}
// 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)
super.flushBefore(pos); // this will call checkClosed() for us
cache.disposeBefore(pos);
|
public boolean | isCached()Returns true since this
ImageInputStream caches data in order to allow
seeking backwards.
return true;
|
public boolean | isCachedFile()Returns false since this
ImageInputStream does not maintain a file cache.
return false;
|
public boolean | isCachedMemory()Returns true since this
ImageInputStream maintains a main memory cache.
return true;
|
public int | read()
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)
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;
}
|