Package org.apache.http.impl.io
Class ChunkedOutputStream
java.lang.Object
java.io.OutputStream
org.apache.http.impl.io.ChunkedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]private intprivate booleanTrue if the stream is closed.private final SessionOutputBufferprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionChunkedOutputStream(int bufferSize, SessionOutputBuffer out) Wraps a session output buffer and chunk-encodes the output.Deprecated.ChunkedOutputStream(SessionOutputBuffer out, int bufferSize) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Finishes writing to the underlying stream, but does NOT close the underlying stream.voidfinish()Must be called to ensure the internal cache is flushed and the closing chunk is written.voidflush()Flushes the content buffer and the underlying stream.protected voidWrites the cache out onto the underlying streamprotected voidflushCacheWithAppend(byte[] bufferToAppend, int off, int len) Writes the cache and bufferToAppend to the underlying stream as one large chunkvoidwrite(byte[] b) Writes the array.voidwrite(byte[] src, int off, int len) Writes the array.voidwrite(int b) protected void
-
Field Details
-
out
-
cache
private final byte[] cache -
cachePosition
private int cachePosition -
wroteLastChunk
private boolean wroteLastChunk -
closed
private boolean closedTrue if the stream is closed.
-
-
Constructor Details
-
ChunkedOutputStream
Deprecated.Wraps a session output buffer and chunk-encodes the output.- Parameters:
out- The session output bufferbufferSize- The minimum chunk size (excluding last chunk)- Throws:
IOException- not thrown
-
ChunkedOutputStream
Deprecated.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- not thrown
-
ChunkedOutputStream
Wraps a session output buffer and chunk-encodes the output.- Parameters:
bufferSize- The minimum chunk size (excluding last chunk)out- The session output buffer
-
-
Method Details
-
flushCache
Writes the cache out onto the underlying stream- Throws:
IOException
-
flushCacheWithAppend
Writes the cache and bufferToAppend to the underlying stream as one large chunk- Throws:
IOException
-
writeClosingChunk
- Throws:
IOException
-
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
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
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:
writein classOutputStream- Throws:
IOException
-
write
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:
writein classOutputStream- Throws:
IOException
-
flush
Flushes the content buffer and the underlying stream.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
Finishes writing to the underlying stream, but does NOT close the underlying stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
ChunkedOutputStream(int, SessionOutputBuffer)