public class

ChunkedOutputStream

extends OutputStream
java.lang.Object
   ↳ java.io.OutputStream
     ↳ org.apache.http.impl.io.ChunkedOutputStream

Class Overview

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.

Summary

Public Constructors
ChunkedOutputStream(SessionOutputBuffer out, int bufferSize)
Wraps a session output buffer and chunk-encodes the output.
ChunkedOutputStream(SessionOutputBuffer out)
Wraps a session output buffer and chunks the output.
Public Methods
void close()
Finishes writing to the underlying stream, but does NOT close the underlying stream.
void finish()
Must be called to ensure the internal cache is flushed and the closing chunk is written.
void flush()
Flushes the content buffer and the underlying stream.
void write(byte[] src, int off, int len)
Writes the array.
void write(byte[] b)
Writes the array.
void write(int b)
Protected Methods
void flushCache()
Writes the cache out onto the underlying stream
void flushCacheWithAppend(byte[] bufferToAppend, int off, int len)
Writes the cache and bufferToAppend to the underlying stream as one large chunk
void writeClosingChunk()
[Expand]
Inherited Methods
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable

Public Constructors

public ChunkedOutputStream (SessionOutputBuffer out, int bufferSize)

Wraps a session output buffer and chunk-encodes the output.

Parameters
out The session output buffer
bufferSize The minimum chunk size (excluding last chunk)
Throws
IOException in case of an I/O error

public ChunkedOutputStream (SessionOutputBuffer out)

Wraps a session output buffer and chunks the output. The default buffer size of 2048 was chosen because the chunk overhead is less than 0.5%

Parameters
out the output buffer to wrap
Throws
IOException in case of an I/O error

Public Methods

public void close ()

Finishes writing to the underlying stream, but does NOT close the underlying stream.

Throws
IOException

public void finish ()

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

public void flush ()

Flushes the content buffer and the underlying stream.

Throws
IOException

public void write (byte[] src, int off, int len)

Writes the array. If the array does not fit within the buffer, it is not split, but rather written out as one large chunk.

Throws
IOException

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.

Throws
IOException

public void write (int b)

Throws
IOException

Protected Methods

protected void flushCache ()

Writes the cache out onto the underlying stream

Throws
IOException

protected void flushCacheWithAppend (byte[] bufferToAppend, int off, int len)

Writes the cache and bufferToAppend to the underlying stream as one large chunk

Throws
IOException

protected void writeClosingChunk ()

Throws
IOException