public class HttpInput extends ServletInputStream implements 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 |
---|---|
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 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. |
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(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 |
isAsyncEOF() |
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 |
nextReadable()
Get the next readable from the inputQ, calling
produceContent() if need be. |
protected HttpInput.Content |
pollNonEmptyContent()
Poll the inputQ for Content.
|
protected HttpInput.Content |
pollReadableContent()
Poll the inputQ for Content or EOF.
|
boolean |
prependContent(HttpInput.Content item)
Adds some content to the start of this input stream.
|
protected void |
produceContent()
Called when derived implementations should attempt to produce more Content and add it via
addContent(Content) . |
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.
|
String |
toString() |
void |
unblock() |
protected void |
wake() |
readLine
close, mark, markSupported, read, reset, skip
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 InputStream
protected void wake()
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
protected void produceContent() throws IOException
addContent(Content)
. For protocols that are constantly
producing (eg HTTP2) this can be left as a noop;IOException
- if unable to produce contentprotected HttpInput.Content nextContent() throws IOException
produceContent()
if need be. EOF is processed and state changed.IOException
- if retrieving the content failsprotected HttpInput.Content pollNonEmptyContent()
HttpInput.SentinelContent
s are removed and EOF state updated if need be.protected HttpInput.Content pollReadableContent()
HttpInput.SentinelContent
s are removed. EOF state is not updated.
Interception is done within this method.HttpInput.SentinelContent
, or nullprotected HttpInput.Content nextReadable() throws IOException
produceContent()
if need be. EOF is NOT processed and state is not changed.IOException
- if retrieving the content failsprotected 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 IOException
IOException
- if the wait is interruptedpublic boolean prependContent(HttpInput.Content item)
Typically used to push back content that has been read, perhaps mutated. The bytes prepended are deducted for the contentConsumed total
item
- the content to addpublic 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 ServletInputStream
public boolean isAsyncEOF()
public boolean isReady()
isReady
in class ServletInputStream
public void setReadListener(ReadListener readListener)
setReadListener
in class ServletInputStream
public boolean failed(Throwable x)
Copyright © 1995–2017 Webtide. All rights reserved.