java.lang.RunnableHttpInputOverHTTPpublic class HttpInput extends 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 | Description |
|---|---|---|
static class |
HttpInput.ChainedInterceptor |
An
HttpInput.Interceptor that chains two other HttpInput.Interceptors 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 | Description |
|---|---|---|
protected static HttpInput.State |
AEOF |
|
protected static HttpInput.State |
ASYNC |
|
protected static HttpInput.State |
EARLY_EOF |
|
protected static HttpInput.State |
EOF |
|
protected static HttpInput.State |
STREAM |
| Constructor | Description |
|---|---|
HttpInput(HttpChannelState state) |
| Modifier and Type | Method | 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.
|
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.
|
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(ReadListener readListener) |
|
protected void |
skip(HttpInput.Content content,
int length) |
Consumes the given content.
|
java.lang.String |
toString() |
|
void |
unblock() |
|
protected void |
wake() |
close, mark, markSupported, read, readAllBytes, readNBytes, reset, skip, transferToclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitreadLineprotected 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.InputStreamprotected void wake()
public int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionprotected 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.SentinelContents 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.SentinelContents are removed. EOF state is not updated.
Interception is done within this method.HttpInput.SentinelContent, or nullprotected 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 ServletInputStreampublic boolean isReady()
isReady in class ServletInputStreampublic void setReadListener(ReadListener readListener)
setReadListener in class ServletInputStreampublic boolean onIdleTimeout(java.lang.Throwable x)
public boolean failed(java.lang.Throwable x)
public void run()
run in interface java.lang.Runnablepublic java.lang.String toString()
toString in class java.lang.ObjectCopyright © 1995–2018 Webtide. All rights reserved.