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.Content |
static class |
HttpInput.EofContent |
protected static class |
HttpInput.EOFState |
protected class |
HttpInput.ErrorState |
static class |
HttpInput.PoisonPillContent |
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 item)
Adds some content to this input stream.
|
int |
available() |
protected void |
blockForContent()
Blocks until some content or some end-of-file event arrives.
|
boolean |
consumeAll() |
protected void |
consumeNonContent() |
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() |
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 |
nextReadable()
Get the next readable from the inputQ, calling
produceContent()
if need be. |
protected HttpInput.Content |
pollContent()
Poll the inputQ for Content.
|
protected HttpInput.Content |
pollReadable()
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() |
protected int |
remaining(HttpInput.Content item) |
void |
run() |
void |
setReadListener(ReadListener readListener) |
protected void |
skip(HttpInput.Content content,
int length)
Consumes the given content.
|
String |
toString() |
void |
unblock() |
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 int available()
available
in class InputStream
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 pollContent()
HttpInput.PoisonPillContent
s are removed and
EOF state updated if need be.protected void consumeNonContent()
protected HttpInput.Content nextReadable() throws IOException
produceContent()
if need be. EOF is NOT processed and state is not changed.IOException
- if retrieving the content failsprotected HttpInput.Content pollReadable()
HttpInput.PoisonPillContent
s are removed.
EOF state is not updated.protected int remaining(HttpInput.Content item)
item
- the contentprotected 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 item)
item
- 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 isReady()
isReady
in class ServletInputStream
public void setReadListener(ReadListener readListener)
setReadListener
in class ServletInputStream
public boolean failed(Throwable x)
Copyright © 1995-2016 Webtide. All Rights Reserved.