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 interface
Set a close listener which will be called when the user closes the stream.private static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final int
private boolean
private ChunkedBodyOutputStream.Listener
private final ByteBuffer
private Filter
<ByteBuffer, ?, ?, ?> private static final ByteBuffer
private final int
private final CountDownLatch
private ChunkedBodyOutputStream.Mode
private boolean
private WriteListener
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
private void
void
close()
protected void
protected void
protected ByteBuffer
encodeToHttp
(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<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 providedWriteListener
when it is possible to write.void
write
(byte[] b, int off, int len) void
write
(int b) protected void
write
(ByteBuffer byteBuffer) Methods inherited from class java.io.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:BodyOutputStream
Instructs the stream to invoke the providedWriteListener
when it is possible to write. If the stream is in UNDECIDED state, invoking this method will commit the stream to ASYNCHRONOUS mode.- Specified by:
setWriteListener
in classBodyOutputStream
- Parameters:
writeListener
- theWriteListener
that should be notified when it's possible to write.
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
isReady
public boolean isReady()Description copied from class:BodyOutputStream
Returns 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, anIllegalStateException
is thrown.- Specified by:
isReady
in classBodyOutputStream
- Returns:
true
if 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-