Methods Summary |
---|
public void | close()Finishes writing to the underlying stream, but does NOT close the underlying stream.
if (!this.closed) {
this.closed = true;
finish();
this.out.flush();
}
|
public void | finish()Must be called to ensure the internal cache is flushed and the closing chunk is written.
if (!this.wroteLastChunk) {
flushCache();
writeClosingChunk();
this.wroteLastChunk = true;
}
|
public void | flush()Flushes the content buffer and the underlying stream.
flushCache();
this.out.flush();
|
protected void | flushCache()Writes the cache out onto the underlying stream
if (this.cachePosition > 0) {
this.out.writeLine(Integer.toHexString(this.cachePosition));
this.out.write(this.cache, 0, this.cachePosition);
this.out.writeLine("");
this.cachePosition = 0;
}
|
protected void | flushCacheWithAppend(byte[] bufferToAppend, int off, int len)Writes the cache and bufferToAppend to the underlying stream
as one large chunk
this.out.writeLine(Integer.toHexString(this.cachePosition + len));
this.out.write(this.cache, 0, this.cachePosition);
this.out.write(bufferToAppend, off, len);
this.out.writeLine("");
this.cachePosition = 0;
|
public void | write(int b)
if (this.closed) {
throw new IOException("Attempted write to closed stream.");
}
this.cache[this.cachePosition] = (byte) b;
this.cachePosition++;
if (this.cachePosition == this.cache.length) flushCache();
|
public void | write(byte[] b)Writes the array. If the array does not fit within the buffer, it is
not split, but rather written out as one large chunk.
write(b, 0, b.length);
|
public void | write(byte[] src, int off, int len)
if (this.closed) {
throw new IOException("Attempted write to closed stream.");
}
if (len >= this.cache.length - this.cachePosition) {
flushCacheWithAppend(src, off, len);
} else {
System.arraycopy(src, off, cache, this.cachePosition, len);
this.cachePosition += len;
}
|
protected void | writeClosingChunk()
// Write the final chunk.
this.out.writeLine("0");
this.out.writeLine("");
|