Description
One of the nice things about chunked encoding is that you can send your data in little parts.
However, flush() on ChunkedOutputStream does not flush the buffer:
/**
- Flushes the underlying stream, but leaves the internal buffer alone.
- @throws IOException
*/
public void flush() throws IOException { this.out.flush(); }
This is kind of against the spec of flush on OutputStream:
/**
- Flushes this output stream and forces any buffered output bytes
- to be written out. The general contract of <code>flush</code> is
- that calling it is an indication that, if any bytes previously
- written have been buffered by the implementation of the output
- stream, such bytes should immediately be written to their
- intended destination.
- ...
Generally if a client does not want to flush the data they won't call flush, which will cause all the chunks to attain the full chunk size anyway...
The fix would be to add a flushCache() call right before this.out.flush(). Currently I'm using my own subclass of ChunkedOutputStream which does exactly this and it works perfectly; the chunks in my application have the full size 99% of the time (unless I explicitly flush in the writeTo(OutputStream) method of my Entity).