public class HttpInput
extends javax.servlet.ServletInputStream
implements java.lang.Runnable
HttpInput
provides an implementation of ServletInputStream
for HttpChannel
.
Content may arrive in patterns such as [content(), content(), messageComplete()] so that this class maintains two states: the content state that tells whether there is content to consume and the EOF state that tells whether an EOF has arrived. Only once the content has been consumed the content state is moved to the EOF state.
Modifier and Type | Class and Description |
---|---|
static class |
HttpInput.ChainedInterceptor
An
HttpInput.Interceptor that chains two other HttpInput.Interceptor s together. |
static class |
HttpInput.Content |
static class |
HttpInput.EofContent |
protected static class |
HttpInput.EOFState |
protected class |
HttpInput.ErrorState |
static interface |
HttpInput.Interceptor
An interceptor for HTTP Request input.
|
static class |
HttpInput.SentinelContent
A Sentinel Content, which has zero length content but
indicates some other event in the input stream (eg EOF)
|
protected static class |
HttpInput.State |
Modifier and Type | Field and Description |
---|---|
private long |
_blockUntil |
private HttpChannelState |
_channelState |
private HttpInput.Content |
_content |
private long |
_contentArrived |
private long |
_contentConsumed |
private long |
_firstByteTimeStamp |
private java.util.Deque<HttpInput.Content> |
_inputQ |
private HttpInput.Content |
_intercepted |
private HttpInput.Interceptor |
_interceptor |
private javax.servlet.ReadListener |
_listener |
private byte[] |
_oneByteBuffer |
private HttpInput.State |
_state |
private boolean |
_waitingForContent |
protected static HttpInput.State |
AEOF |
protected static HttpInput.State |
ASYNC |
protected static HttpInput.State |
EARLY_EOF |
(package private) static HttpInput.Content |
EARLY_EOF_CONTENT |
protected static HttpInput.State |
EOF |
(package private) static HttpInput.Content |
EOF_CONTENT |
private static Logger |
LOG |
protected static HttpInput.State |
STREAM |
Constructor and Description |
---|
HttpInput(HttpChannelState state) |
Modifier and Type | Method and Description |
---|---|
boolean |
addContent(HttpInput.Content content)
Adds some content to this input stream.
|
void |
addInterceptor(HttpInput.Interceptor interceptor)
Set the
HttpInput.Interceptor , using a HttpInput.ChainedInterceptor if
an HttpInput.Interceptor is already set. |
void |
asyncReadProduce()
Called by channel when asynchronous IO needs to produce more content
|
int |
available() |
protected void |
blockForContent()
Blocks until some content or some end-of-file event arrives.
|
private void |
consume(HttpInput.Content content) |
boolean |
consumeAll() |
boolean |
earlyEOF()
This method should be called to signal that an EOF has been detected before all the expected content arrived.
|
boolean |
eof()
This method should be called to signal that all the expected content arrived.
|
boolean |
failed(java.lang.Throwable x) |
protected int |
get(HttpInput.Content content,
byte[] buffer,
int offset,
int length)
Copies the given content into the given byte buffer.
|
private long |
getBlockingTimeout() |
long |
getContentConsumed() |
protected HttpChannelState |
getHttpChannelState() |
HttpInput.Interceptor |
getInterceptor() |
boolean |
hasContent() |
boolean |
isAsync() |
boolean |
isError() |
boolean |
isFinished() |
boolean |
isReady() |
protected HttpInput.Content |
nextContent()
Get the next content from the inputQ, calling
produceContent() if need be. |
protected HttpInput.Content |
nextInterceptedContent()
Poll the inputQ for Content or EOF.
|
protected HttpInput.Content |
nextNonSentinelContent()
Poll the inputQ for Content.
|
boolean |
onIdleTimeout(java.lang.Throwable x) |
protected void |
produceContent()
Called when derived implementations should attempt to produce more Content and add it via
addContent(Content) . |
protected HttpInput.Content |
produceNextContext()
Get the next readable from the inputQ, calling
produceContent() if need be. |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
recycle() |
void |
run() |
void |
setInterceptor(HttpInput.Interceptor interceptor)
Set the interceptor.
|
void |
setReadListener(javax.servlet.ReadListener readListener) |
protected void |
skip(HttpInput.Content content,
int length)
Consumes the given content.
|
java.lang.String |
toString() |
void |
unblock() |
protected void |
wake() |
private boolean |
wakeup() |
private static final Logger LOG
static final HttpInput.Content EOF_CONTENT
static final HttpInput.Content EARLY_EOF_CONTENT
private final byte[] _oneByteBuffer
private HttpInput.Content _content
private HttpInput.Content _intercepted
private final java.util.Deque<HttpInput.Content> _inputQ
private final HttpChannelState _channelState
private javax.servlet.ReadListener _listener
private HttpInput.State _state
private long _firstByteTimeStamp
private long _contentArrived
private long _contentConsumed
private long _blockUntil
private boolean _waitingForContent
private HttpInput.Interceptor _interceptor
protected static final HttpInput.State STREAM
protected static final HttpInput.State ASYNC
protected static final HttpInput.State EARLY_EOF
protected static final HttpInput.State EOF
protected static final HttpInput.State AEOF
public HttpInput(HttpChannelState state)
protected HttpChannelState getHttpChannelState()
public void recycle()
public HttpInput.Interceptor getInterceptor()
public void setInterceptor(HttpInput.Interceptor interceptor)
interceptor
- The interceptor to use.public void addInterceptor(HttpInput.Interceptor interceptor)
HttpInput.Interceptor
, using a HttpInput.ChainedInterceptor
if
an HttpInput.Interceptor
is already set.interceptor
- the next HttpInput.Interceptor
in a chainpublic int available()
available
in class java.io.InputStream
protected void wake()
private long getBlockingTimeout()
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
protected void produceContent() throws java.io.IOException
addContent(Content)
. For protocols that are constantly
producing (eg HTTP2) this can be left as a noop;java.io.IOException
- if unable to produce contentpublic void asyncReadProduce() throws java.io.IOException
java.io.IOException
- if unable to produce contentprotected HttpInput.Content nextContent() throws java.io.IOException
produceContent()
if need be. EOF is processed and state changed.java.io.IOException
- if retrieving the content failsprotected HttpInput.Content nextNonSentinelContent()
HttpInput.SentinelContent
s are removed and EOF state updated if need be.protected HttpInput.Content produceNextContext() throws java.io.IOException
produceContent()
if need be. EOF is NOT processed and state is not changed.java.io.IOException
- if retrieving the content failsprotected HttpInput.Content nextInterceptedContent()
HttpInput.SentinelContent
s are removed. EOF state is not updated.
Interception is done within this method.HttpInput.SentinelContent
, or nullprivate void consume(HttpInput.Content content)
protected int get(HttpInput.Content content, byte[] buffer, int offset, int length)
content
- the content to copy frombuffer
- the buffer to copy intooffset
- the buffer offset to start copying fromlength
- the space available in the bufferprotected void skip(HttpInput.Content content, int length)
content
- the content to consumelength
- the number of bytes to consumeprotected void blockForContent() throws java.io.IOException
java.io.IOException
- if the wait is interruptedpublic boolean addContent(HttpInput.Content content)
content
- the content to addpublic boolean hasContent()
public void unblock()
public long getContentConsumed()
public boolean earlyEOF()
Typically this will result in an EOFException being thrown from a subsequent read rather than a -1 return.
public boolean eof()
public boolean consumeAll()
public boolean isError()
public boolean isAsync()
public boolean isFinished()
isFinished
in class javax.servlet.ServletInputStream
public boolean isReady()
isReady
in class javax.servlet.ServletInputStream
public void setReadListener(javax.servlet.ReadListener readListener)
setReadListener
in class javax.servlet.ServletInputStream
public boolean onIdleTimeout(java.lang.Throwable x)
public boolean failed(java.lang.Throwable x)
private boolean wakeup()
public void run()
run
in interface java.lang.Runnable
public java.lang.String toString()
toString
in class java.lang.Object