class ChunkedBodyOutputStream extends BodyOutputStream
BodyOutputStream
for details.Modifier and Type | Class and Description |
---|---|
(package private) static interface |
ChunkedBodyOutputStream.Listener
Set a close listener which will be called when the user closes the stream.
|
private static class |
ChunkedBodyOutputStream.Mode |
Modifier and Type | Field and Description |
---|---|
private boolean |
callListener |
private int |
chunkSize |
private boolean |
closed |
private ChunkedBodyOutputStream.Listener |
closeListener |
private java.nio.ByteBuffer |
dataBuffer |
private Filter<java.nio.ByteBuffer,?,?,?> |
downstreamFilter |
private static java.nio.ByteBuffer |
EMPTY_BUFFER |
private int |
encodedFullChunkSize |
private java.util.concurrent.CountDownLatch |
initialBlockingLatch |
private ChunkedBodyOutputStream.Mode |
mode |
private boolean |
ready |
private WriteListener |
writeListener |
Constructor and Description |
---|
ChunkedBodyOutputStream(int chunkSize) |
Modifier and Type | Method and Description |
---|---|
private void |
assertAsynchronousOperation() |
private void |
assertValidState() |
private void |
callOnWritePossible() |
void |
close() |
protected void |
commitToMode() |
protected void |
doInitialBlocking() |
protected java.nio.ByteBuffer |
encodeToHttp(java.nio.ByteBuffer byteBuffer)
Transform raw application data into HTTP body.
|
void |
flush() |
boolean |
isReady()
Returns true if data can be written without blocking else returns
false.
|
(package private) void |
open(Filter<java.nio.ByteBuffer,?,?,?> downstreamFilter) |
(package private) void |
setCloseListener(ChunkedBodyOutputStream.Listener closeListener)
Set a close listener which will be called when the user closes the stream.
|
void |
setWriteListener(WriteListener writeListener)
Instructs the stream to invoke the provided
WriteListener when it is possible to write. |
void |
write(byte[] b,
int off,
int len) |
protected void |
write(java.nio.ByteBuffer byteBuffer) |
void |
write(int b) |
private static final java.nio.ByteBuffer EMPTY_BUFFER
private final int chunkSize
private final int encodedFullChunkSize
private final java.nio.ByteBuffer dataBuffer
private final java.util.concurrent.CountDownLatch initialBlockingLatch
private volatile Filter<java.nio.ByteBuffer,?,?,?> downstreamFilter
private volatile WriteListener writeListener
private volatile ChunkedBodyOutputStream.Listener closeListener
private volatile ChunkedBodyOutputStream.Mode mode
private volatile boolean ready
private volatile boolean callListener
private volatile boolean closed
public void setWriteListener(WriteListener writeListener)
BodyOutputStream
WriteListener
when it is possible to write.
If the stream is in UNDECIDED state, invoking this method will commit the stream to ASYNCHRONOUS mode.setWriteListener
in class BodyOutputStream
writeListener
- the WriteListener
that should be notified
when it's possible to write.public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public boolean isReady()
BodyOutputStream
IllegalStateException
is thrown.isReady
in class BodyOutputStream
true
if data can be obtained without blocking,
otherwise returns false
.private void assertValidState()
protected void write(java.nio.ByteBuffer byteBuffer) throws java.io.IOException
java.io.IOException
void open(Filter<java.nio.ByteBuffer,?,?,?> downstreamFilter)
protected void doInitialBlocking() throws java.io.IOException
java.io.IOException
protected void commitToMode()
private void assertAsynchronousOperation()
private void callOnWritePossible()
void setCloseListener(ChunkedBodyOutputStream.Listener closeListener)
closeListener
- close listener.protected java.nio.ByteBuffer encodeToHttp(java.nio.ByteBuffer byteBuffer)
byteBuffer
- application data.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException