Class BodyOutputStream
java.lang.Object
java.io.OutputStream
org.glassfish.jersey.jdk.connector.internal.BodyOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
- Direct Known Subclasses:
BufferedBodyOutputStream,ChunkedBodyOutputStream
TODO consider exposing the mode as part of the API, so the user can make decisions based on the mode
An extension of
OutputStream that adds method that allow to use the stream asynchronously.
It is inspired by and works in a very similar way as Servlet asynchronous streams introduced in Servlet 3.1.
The stream supports 2 modes SYNCHRONOUS and ASYNCHRONOUS.
The stream is one of the following 3 states:
- UNDECIDED
- SYNCHRONOUS
- ASYNCHRONOUS
setWriteListener(WriteListener) is invoked before any of the write methods, it commits to ASYNCHRONOUS
mode and similarly if any of the write methods is invoked before setWriteListener(WriteListener),
it commits to SYNCHRONOUS mode.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanisReady()Returns true if data can be written without blocking else returns false.abstract voidsetWriteListener(WriteListener writeListener) Instructs the stream to invoke the providedWriteListenerwhen it is possible to write.Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write, write, write
-
Constructor Details
-
BodyOutputStream
BodyOutputStream()
-
-
Method Details
-
setWriteListener
Instructs 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.- Parameters:
writeListener- theWriteListenerthat should be notified when it's possible to write.- Throws:
IllegalStateException- if one of the following conditions is true- the stream has already committed to SYNCHRONOUS mode.
- setWriteListener is called more than once within the scope of the same request.
NullPointerException- if writeListener is null
-
isReady
public abstract boolean isReady()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, anIllegalStateExceptionis thrown.- Returns:
trueif data can be obtained without blocking, otherwise returnsfalse.
-