Android APIs
public class

ChunkedOutputStream

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

Class Overview

Implements chunked transfer coding. See RFC 2616, section 3.6.1. Writes are buffered to an internal buffer (2048 default size).

Summary

Public Constructors
ChunkedOutputStream(SessionOutputBuffer out, int bufferSize)
Wraps a session output buffer and chunks 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 count bytes from the byte array buffer starting at position offset to this stream.
void write(byte[] b)
Writes the array.
void write(int b)
Writes a single byte to this stream.
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
From interface java.lang.AutoCloseable

Public Constructors

public ChunkedOutputStream (SessionOutputBuffer out, int bufferSize)

Added in API level 1

Wraps a session output buffer and chunks the output.

Parameters
out the session output buffer to wrap
bufferSize minimum chunk size (excluding last chunk)
Throws
IOException

public ChunkedOutputStream (SessionOutputBuffer out)

Added in API level 1

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

Public Methods

public void close ()

Added in API level 1

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

Throws
IOException

public void finish ()

Added in API level 1

Must be called to ensure the internal cache is flushed and the closing chunk is written.

Throws
IOException

public void flush ()

Added in API level 1

Flushes the content buffer and the underlying stream.

Throws
IOException

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

Added in API level 1

Writes count bytes from the byte array buffer starting at position offset to this stream.

Parameters
src the buffer to be written.
off the start position in buffer from where to get bytes.
len the number of bytes from buffer to write to this stream.
Throws
IOException

public void write (byte[] b)

Added in API level 1

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)

Added in API level 1

Writes a single byte to this stream. Only the least significant byte of the integer oneByte is written to the stream.

Parameters
b the byte to be written.
Throws
IOException

Protected Methods

protected void flushCache ()

Added in API level 1

Writes the cache out onto the underlying stream

Throws
IOException

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

Added in API level 1

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

Throws
IOException

protected void writeClosingChunk ()

Added in API level 1

Throws
IOException