org.apache.commons.httpclient

Class ChunkedOutputStream

Implemented Interfaces:
Closeable, Flushable

public class ChunkedOutputStream
extends OutputStream

Implements HTTP chunking support. 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).

Constructor Summary

ChunkedOutputStream(OutputStream stream)
Wraps a stream and chunks the output.
ChunkedOutputStream(OutputStream stream, int bufferSize)
Wraps a stream and chunks the output.

Method Summary

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.
protected void
flushCache()
Writes the cache out onto the underlying stream
protected void
flushCacheWithAppend(bufferToAppend[] , int off, int len)
Writes the cache and bufferToAppend to the underlying stream as one large chunk
void
write(b[] )
Writes the array.
void
write(int b)
Write the specified byte to our output stream.
void
write(src[] , int off, int len)
protected void
writeClosingChunk()

Methods inherited from class java.io.OutputStream

close, flush, write, write, write

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

ChunkedOutputStream

public ChunkedOutputStream(OutputStream stream)
            throws IOException
Wraps a stream and chunks the output. The default buffer size of 2048 was chosen because the chunk overhead is less than 0.5%
Parameters:
stream -
Throws:
IOException -
Usages and Demos :

View More Examples of ChunkedOutputStream(OutputStream stream)
   1:                 if (transferenc.getValue().indexOf("chunked") != -1) {
   2:                     outsream = new ChunkedOutputStream(outsream);
   3:                 }
   4:         ...
   5:                 if (transferenc.getValue().indexOf("chunked") != -1) {
   6:                     outsream = new ChunkedOutputStream(outsream);
   7:                 }
   8:             }
   9:                         

View Full Code Here
   1:         if (contentLength < 0) {
   2:             outstream = new ChunkedOutputStream(outstream);
   3:         }
   4:         
   5:         requestEntity.writeRequest(outstream);

View Full Code Here

ChunkedOutputStream

public ChunkedOutputStream(OutputStream stream,
                           int bufferSize)
            throws IOException
Wraps a stream and chunks the output.
Parameters:
stream - to wrap
bufferSize - minimum chunk size (excluding last chunk)
Throws:
IOException -
Since:
3.0

Method Details

close

public void close()
            throws IOException
Finishes writing to the underlying stream, but does NOT close the underlying stream.
Specified by:
close in interface Closeable
Overrides:
close in interface OutputStream
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 -
Since:
3.0

flush

public void flush()
            throws IOException
Flushes the underlying stream, but leaves the internal buffer alone.
Specified by:
flush in interface Flushable
Overrides:
flush in interface OutputStream
Throws:
IOException -

flushCache

protected void flushCache()
            throws IOException
Writes the cache out onto the underlying stream
Throws:
IOException -
Since:
3.0

flushCacheWithAppend

protected void flushCacheWithAppend(bufferToAppend[] ,
                                    int off,
                                    int len)
            throws IOException
Writes the cache and bufferToAppend to the underlying stream as one large chunk
Parameters:
off -
len -
Throws:
IOException -
Since:
3.0

write

public void write(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 interface OutputStream
Parameters:
Throws:
IOException -
Since:
3.0

write

public void write(int b)
            throws IOException
Write the specified byte to our output stream. Note: Avoid this method as it will cause an inefficient single byte chunk. Use write (byte[], int, int) instead.
Overrides:
write in interface OutputStream
Parameters:
b - The byte to be written
Throws:
IOException - if an input/output error occurs

write

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

writeClosingChunk

protected void writeClosingChunk()
            throws IOException