Package org.apache.http.impl.io
Class ChunkedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.http.impl.io.ChunkedOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class ChunkedOutputStream extends java.io.OutputStream
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
-
-
Constructor Summary
Constructors Constructor Description ChunkedOutputStream(int bufferSize, SessionOutputBuffer out)
Wraps a session output buffer and chunk-encodes the output.ChunkedOutputStream(SessionOutputBuffer out)
Deprecated.ChunkedOutputStream(SessionOutputBuffer out, int bufferSize)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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[] b)
Writes the array.void
write(byte[] src, int off, int len)
Writes the array.void
write(int b)
-
-
-
Constructor Detail
-
ChunkedOutputStream
@Deprecated public ChunkedOutputStream(SessionOutputBuffer out, int bufferSize) throws java.io.IOException
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:
java.io.IOException
- not thrown
-
ChunkedOutputStream
@Deprecated public ChunkedOutputStream(SessionOutputBuffer out) throws java.io.IOException
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:
java.io.IOException
- not thrown
-
ChunkedOutputStream
public ChunkedOutputStream(int bufferSize, SessionOutputBuffer out)
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 Detail
-
finish
public void finish() throws java.io.IOException
Must be called to ensure the internal cache is flushed and the closing chunk is written.- Throws:
java.io.IOException
- in case of an I/O error
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.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 classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] src, int off, int len) throws java.io.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 classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
Flushes the content buffer and the underlying stream.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Finishes writing to the underlying stream, but does NOT close the underlying stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
-