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:
Closeable, Flushable, AutoCloseable
Body stream that can operate either synchronously or asynchronously. See
BodyOutputStream for details.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interfaceSet a close listener which will be called when the user closes the stream.private static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final intprivate booleanprivate ChunkedBodyOutputStream.Listenerprivate final ByteBufferprivate Filter<ByteBuffer, ?, ?, ?> private static final ByteBufferprivate final intprivate final CountDownLatchprivate ChunkedBodyOutputStream.Modeprivate booleanprivate WriteListener -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidprivate voidvoidclose()protected voidprotected voidprotected ByteBufferencodeToHttp(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<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(ByteBuffer byteBuffer) Methods inherited from class OutputStream
nullOutputStream, write
-
Field Details
-
EMPTY_BUFFER
-
chunkSize
private final int chunkSize -
encodedFullChunkSize
private final int encodedFullChunkSize -
dataBuffer
-
initialBlockingLatch
-
downstreamFilter
-
writeListener
-
closeListener
-
mode
-
ready
private volatile boolean ready -
callListener
private volatile boolean callListener -
closed
private volatile boolean closed
-
-
Constructor Details
-
ChunkedBodyOutputStream
ChunkedBodyOutputStream(int chunkSize)
-
-
Method Details
-
setWriteListener
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
- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
write
- Specified by:
writein classOutputStream- Throws:
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
- Throws:
IOException
-
open
-
doInitialBlocking
- Throws:
IOException
-
commitToMode
protected void commitToMode() -
assertAsynchronousOperation
private void assertAsynchronousOperation() -
callOnWritePossible
private void callOnWritePossible() -
setCloseListener
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
Transform raw application data into HTTP body.- Parameters:
byteBuffer- application data.- Returns:
- http body part.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-