English | Site Directory

Android - An Open Handset Alliance Project

org.apache.http.impl.io.ChunkedOutputStream

java.lang.Object
java.io.OutputStream Closeable Flushable
org.apache.http.impl.io.ChunkedOutputStream

Implements chunked transfer coding. See RFC 2616, section 3.6.1. Writes are buffered to an internal buffer (2048 default size). Chunks are guaranteed to be at least as large as the buffer size (except for the last chunk).

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 underlying stream, but leaves the internal buffer alone.
        void  write(byte[] b)
Writes the array.
        void  write(int b)
Writes the specified byte oneByte to this OutputStream.
        void  write(byte[] src, int off, int len)
Writes count bytes from the byte array buffer starting at offset to this OutputStream.

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()
Methods inherited from class java.io.OutputStream
Methods inherited from class java.lang.Object
Methods inherited from interface java.io.Closeable
Methods inherited from interface java.io.Flushable

Details

Public Constructors

public ChunkedOutputStream(SessionOutputBuffer out, int bufferSize)

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)

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()

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

public void flush()

Flushes the underlying stream, but leaves the internal buffer alone.

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.

Parameters

b the buffer to be written

Throws

IOException

public void write(int b)

Writes the specified byte oneByte to this OutputStream. Only the low order byte of oneByte is written.

Parameters

b the byte to be written

Throws

IOException

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

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

Parameters

src the buffer to be written
off offset in buffer to get bytes
len number of bytes in buffer to write

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
Build m5-rc15i - 10 Jun 2008 13:54