Package hudson.util
Class ChunkedOutputStream
java.lang.Object
java.io.OutputStream
hudson.util.ChunkedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
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).
- Author:
- Mohammad Rezaei, Goldman, Sachs & Co.
-
Constructor Summary
ConstructorsConstructorDescriptionChunkedOutputStream(OutputStream stream) Wraps a stream and chunks the output.ChunkedOutputStream(OutputStream stream, int bufferSize) Wraps a stream and chunks the output. -
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 underlying stream, but leaves the internal buffer alone.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) voidwrite(int b) Write the specified byte to our output stream.protected voidMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
ChunkedOutputStream
Wraps a stream and chunks the output.- Parameters:
stream- to wrapbufferSize- minimum chunk size (excluding last chunk)- Throws:
IOException- Since:
- 3.0
-
ChunkedOutputStream
Wraps a stream and chunks the output. The default buffer size of 2048 was chosen because the chunk overhead is less than 0.5%- Throws:
IOException
-
-
Method Details
-
flushCache
Writes the cache out onto the underlying stream- Throws:
IOException- Since:
- 3.0
-
flushCacheWithAppend
Writes the cache and bufferToAppend to the underlying stream as one large chunk- Throws:
IOException- Since:
- 3.0
-
writeClosingChunk
- Throws:
IOException
-
finish
Must be called to ensure the internal cache is flushed and the closing chunk is written.- Throws:
IOException- Since:
- 3.0
-
write
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.- Specified by:
writein classOutputStream- Parameters:
b- The byte to be written- Throws:
IOException- if an input/output error occurs
-
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- Since:
- 3.0
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
Flushes the underlying stream, but leaves the internal buffer alone.- 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
-