Methods Summary |
---|
public void | close()Closes this FileCacheImageOututStream . All
pending data is flushed to the output, and the cache file
is closed and removed. The destination OutputStream
is not closed.
maxStreamPos = cache.length();
seek(maxStreamPos);
flushBefore(maxStreamPos);
super.close();
cache.close();
cache = null;
cacheFile.delete();
cacheFile = null;
stream.flush();
stream = null;
StreamCloser.removeFromQueue(this);
|
public void | flushBefore(long pos)
long oFlushedPos = flushedPos;
super.flushBefore(pos); // this will call checkClosed() for us
long flushBytes = flushedPos - oFlushedPos;
if (flushBytes > 0) {
int bufLen = 512;
byte[] buf = new byte[bufLen];
cache.seek(oFlushedPos);
while (flushBytes > 0) {
int len = (int)Math.min(flushBytes, bufLen);
cache.readFully(buf, 0, len);
stream.write(buf, 0, len);
flushBytes -= len;
}
stream.flush();
}
|
public boolean | isCached()Returns true since this
ImageOutputStream caches data in order to allow
seeking backwards.
return true;
|
public boolean | isCachedFile()Returns true since this
ImageOutputStream maintains a file cache.
return true;
|
public boolean | isCachedMemory()Returns false since this
ImageOutputStream does not maintain a main memory
cache.
return false;
|
public long | length()
try {
checkClosed();
return cache.length();
} catch (IOException e) {
return -1L;
}
|
public int | read()
checkClosed();
bitOffset = 0;
int val = cache.read();
if (val != -1) {
++streamPos;
}
return val;
|
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;
}
int nbytes = cache.read(b, off, len);
if (nbytes != -1) {
streamPos += nbytes;
}
return nbytes;
|
public void | seek(long pos)Sets the current stream position and resets the bit offset to
0. It is legal to seek past the end of the file; an
EOFException will be thrown only if a read is
performed. The file length will not be increased until a write
is performed.
checkClosed();
if (pos < flushedPos) {
throw new IndexOutOfBoundsException();
}
cache.seek(pos);
this.streamPos = cache.getFilePointer();
maxStreamPos = Math.max(maxStreamPos, streamPos);
this.bitOffset = 0;
|
public void | write(int b)
flushBits(); // this will call checkClosed() for us
cache.write(b);
++streamPos;
maxStreamPos = Math.max(maxStreamPos, streamPos);
|
public void | write(byte[] b, int off, int len)
flushBits(); // this will call checkClosed() for us
cache.write(b, off, len);
streamPos += len;
maxStreamPos = Math.max(maxStreamPos, streamPos);
|