Class ChunkedBodyOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.glassfish.jersey.jdk.connector.internal.BodyOutputStream
-
- org.glassfish.jersey.jdk.connector.internal.ChunkedBodyOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
class ChunkedBodyOutputStream extends BodyOutputStream
Body stream that can operate either synchronously or asynchronously. SeeBodyOutputStreamfor details.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceChunkedBodyOutputStream.ListenerSet a close listener which will be called when the user closes the stream.private static classChunkedBodyOutputStream.Mode
-
Field Summary
Fields Modifier and Type Field Description private booleancallListenerprivate intchunkSizeprivate booleanclosedprivate ChunkedBodyOutputStream.ListenercloseListenerprivate java.nio.ByteBufferdataBufferprivate Filter<java.nio.ByteBuffer,?,?,?>downstreamFilterprivate static java.nio.ByteBufferEMPTY_BUFFERprivate intencodedFullChunkSizeprivate java.util.concurrent.CountDownLatchinitialBlockingLatchprivate ChunkedBodyOutputStream.Modemodeprivate booleanreadyprivate WriteListenerwriteListener
-
Constructor Summary
Constructors Constructor Description ChunkedBodyOutputStream(int chunkSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidassertAsynchronousOperation()private voidassertValidState()private voidcallOnWritePossible()voidclose()protected voidcommitToMode()protected voiddoInitialBlocking()protected java.nio.ByteBufferencodeToHttp(java.nio.ByteBuffer byteBuffer)Transform raw application data into HTTP body.voidflush()booleanisReady()Returns true if data can be written without blocking else returns false.(package private) voidopen(Filter<java.nio.ByteBuffer,?,?,?> downstreamFilter)(package private) voidsetCloseListener(ChunkedBodyOutputStream.Listener closeListener)Set a close listener which will be called when the user closes the stream.voidsetWriteListener(WriteListener writeListener)Instructs the stream to invoke the providedWriteListenerwhen it is possible to write.voidwrite(byte[] b, int off, int len)voidwrite(int b)protected voidwrite(java.nio.ByteBuffer byteBuffer)
-
-
-
Field Detail
-
EMPTY_BUFFER
private static final java.nio.ByteBuffer EMPTY_BUFFER
-
chunkSize
private final int chunkSize
-
encodedFullChunkSize
private final int encodedFullChunkSize
-
dataBuffer
private final java.nio.ByteBuffer dataBuffer
-
initialBlockingLatch
private final java.util.concurrent.CountDownLatch initialBlockingLatch
-
downstreamFilter
private volatile Filter<java.nio.ByteBuffer,?,?,?> downstreamFilter
-
writeListener
private volatile WriteListener writeListener
-
closeListener
private volatile ChunkedBodyOutputStream.Listener closeListener
-
mode
private volatile ChunkedBodyOutputStream.Mode mode
-
ready
private volatile boolean ready
-
callListener
private volatile boolean callListener
-
closed
private volatile boolean closed
-
-
Method Detail
-
setWriteListener
public void setWriteListener(WriteListener writeListener)
Description copied from class:BodyOutputStreamInstructs the stream to invoke the providedWriteListenerwhen it is possible to write. If the stream is in UNDECIDED state, invoking this method will commit the stream to ASYNCHRONOUS mode.- Specified by:
setWriteListenerin classBodyOutputStream- Parameters:
writeListener- theWriteListenerthat should be notified when it's possible to write.
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
isReady
public boolean isReady()
Description copied from class:BodyOutputStreamReturns true if data can be written without blocking else returns false. If the stream is in ASYNCHRONOUS mode and the user attempts to write to it even though this method returns false, anIllegalStateExceptionis thrown.- Specified by:
isReadyin classBodyOutputStream- Returns:
trueif data can be obtained without blocking, otherwise returnsfalse.
-
assertValidState
private void assertValidState()
-
write
protected void write(java.nio.ByteBuffer byteBuffer) throws java.io.IOException- Throws:
java.io.IOException
-
open
void open(Filter<java.nio.ByteBuffer,?,?,?> downstreamFilter)
-
doInitialBlocking
protected void doInitialBlocking() throws java.io.IOException- Throws:
java.io.IOException
-
commitToMode
protected void commitToMode()
-
assertAsynchronousOperation
private void assertAsynchronousOperation()
-
callOnWritePossible
private void callOnWritePossible()
-
setCloseListener
void setCloseListener(ChunkedBodyOutputStream.Listener closeListener)
Set a close listener which will be called when the user closes the stream. This is used to indicate that the body has been completely written.- Parameters:
closeListener- close listener.
-
encodeToHttp
protected java.nio.ByteBuffer encodeToHttp(java.nio.ByteBuffer byteBuffer)
Transform raw application data into HTTP body.- Parameters:
byteBuffer- application data.- Returns:
- http body part.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
-