Methods Summary |
---|
public void | close()Closes this MemoryCacheImageOutputStream . All
pending data is flushed to the output, and the cache
is released. The destination OutputStream
is not closed.
long length = cache.getLength();
seek(length);
flushBefore(length);
super.close();
cache.reset();
stream = null;
|
public void | flushBefore(long pos)
long oFlushedPos = flushedPos;
super.flushBefore(pos);
long flushBytes = flushedPos - oFlushedPos;
cache.writeToStream(stream, oFlushedPos, flushBytes);
cache.disposeBefore(flushedPos);
stream.flush();
|
public boolean | isCached()Returns true since this
ImageOutputStream caches data in order to allow
seeking backwards.
return true;
|
public boolean | isCachedFile()Returns false since this
ImageOutputStream does not maintain a file cache.
return false;
|
public boolean | isCachedMemory()Returns true since this
ImageOutputStream maintains a main memory cache.
return true;
|
public long | length()
return cache.getLength();
|
public int | read()
checkClosed();
bitOffset = 0;
int val = cache.read(streamPos);
if (val != -1) {
++streamPos;
}
return val;
|
public int | read(byte[] b, int off, int len)
checkClosed();
// Fix 4467619: read([B,I,I) doesn't throw NPE as specified
// Fix 4467608: read([B,I,I) works incorrectly if len<=0
// Will throw NullPointerException if b == null
// Will throw IIOBE if off, len are bad args
if (off < 0 || len < 0 || off + len > b.length || off + len < 0) {
throw new IndexOutOfBoundsException
("off < 0 || len < 0 || off + len > b.length!");
}
bitOffset = 0;
if (len == 0) {
return 0;
}
// check if we're already at/past EOF i.e.
// no more bytes left to read from cache
long bytesLeftInCache = cache.getLength() - streamPos;
if (bytesLeftInCache <= 0) {
return -1; // EOF
}
// guaranteed by now that bytesLeftInCache > 0 && len > 0
// and so the rest of the error checking is done by cache.read()
// NOTE that alot of error checking is duplicated
len = (int)Math.min(bytesLeftInCache, (long)len);
cache.read(b, off, len, streamPos);
streamPos += len;
return len;
|
public void | write(int b)
checkClosed();
flushBits();
cache.write(b, streamPos);
++streamPos;
|
public void | write(byte[] b, int off, int len)
checkClosed();
flushBits();
cache.write(b, off, len, streamPos);
streamPos += len;
|