Class ChunkedOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    public class ChunkedOutputStream
    extends OutputStream
    Implements chunked transfer coding. The content is sent in small chunks. Entities transferred using this output stream can be of unlimited length. Writes are buffered to an internal buffer (2048 default size).

    Note that this class NEVER closes the underlying stream, even when close gets called. Instead, the stream will be marked as closed and no further output will be permitted.

    Since:
    4.0
    • Method Detail

      • flushCache

        protected void flushCache()
                           throws IOException
        Writes the cache out onto the underlying stream
        Throws:
        IOException
      • flushCacheWithAppend

        protected void flushCacheWithAppend​(byte[] bufferToAppend,
                                            int off,
                                            int len)
                                     throws IOException
        Writes the cache and bufferToAppend to the underlying stream as one large chunk
        Throws:
        IOException
      • finish

        public void finish()
                    throws IOException
        Must be called to ensure the internal cache is flushed and the closing chunk is written.
        Throws:
        IOException - in case of an I/O error
      • write

        public void write​(byte[] b)
                   throws IOException
        Writes the array. If the array does not fit within the buffer, it is not split, but rather written out as one large chunk.
        Overrides:
        write in class OutputStream
        Throws:
        IOException
      • write

        public void write​(byte[] src,
                          int off,
                          int len)
                   throws IOException
        Writes the array. If the array does not fit within the buffer, it is not split, but rather written out as one large chunk.
        Overrides:
        write in class OutputStream
        Throws:
        IOException