Class BodyInputStream
java.lang.Object
java.io.InputStream
org.glassfish.jersey.internal.util.collection.NonBlockingInputStream
org.glassfish.jersey.jdk.connector.internal.BodyInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
AsynchronousBodyInputStream
TODO consider exposing the mode as part of the API, so the user can make decisions based on the mode
An extension of
NonBlockingInputStream
that adds methods that enable using the stream asynchronously.
The asynchronous mode is inspired by and works in a very similar way as Servlet asynchronous streams introduced in Servlet
3.1.
The stream supports 2 modes of operation SYNCHRONOUS and ASYNCHRONOUS.
The stream is one of the following 3 states:
- UNDECIDED
- SYNCHRONOUS
- ASYNCHRONOUS
setReadListener(ReadListener)
is invoked before any of the read or tryRead methods, it commits to ASYNCHRONOUS
mode and similarly if any of the read or tryRead methods is invoked before setReadListener(ReadListener)
,
it commits to SYNCHRONOUS mode.-
Field Summary
Fields inherited from class org.glassfish.jersey.internal.util.collection.NonBlockingInputStream
NOTHING
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
isReady()
Returns true if data can be read without blocking else returns false.abstract void
setReadListener
(ReadListener readListener) Instructs the stream to invoke the providedReadListener
when it is possible to read.Methods inherited from class org.glassfish.jersey.internal.util.collection.NonBlockingInputStream
available, tryRead, tryRead, tryRead
Methods inherited from class java.io.InputStream
close, mark, markSupported, nullInputStream, read, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
BodyInputStream
BodyInputStream()
-
-
Method Details
-
isReady
public abstract boolean isReady()Returns true if data can be read without blocking else returns false. If the stream is in ASYNCHRONOUS mode and the user attempts to read from it even though this method returns false, anIllegalStateException
is thrown.- Returns:
true
if data can be obtained without blocking, otherwise returnsfalse
.
-
setReadListener
Instructs the stream to invoke the providedReadListener
when it is possible to read. If the stream is in UNDECIDED state, invoking this method will commit the stream to ASYNCHRONOUS mode.- Parameters:
readListener
- theReadListener
that should be notified when it's possible to read.- Throws:
IllegalStateException
- if one of the following conditions is true- the stream has already committed to SYNCHRONOUS mode.
- setReadListener is called more than once within the scope of the same request.
NullPointerException
- if readListener is null
-