public abstract class HttpInput<T> 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 |
---|---|
protected static class |
HttpInput.State |
Modifier and Type | Field and Description |
---|---|
protected static HttpInput.State |
ASYNC |
protected static HttpInput.State |
EARLY_EOF |
protected static HttpInput.State |
EOF |
protected static HttpInput.State |
STREAM |
Modifier | Constructor and Description |
---|---|
protected |
HttpInput() |
protected |
HttpInput(Object lock) |
Modifier and Type | Method and Description |
---|---|
int |
available() |
protected abstract void |
blockForContent()
Blocks until some content or some end-of-file event arrives.
|
protected abstract void |
consume(T item,
int length)
Consumes the given content.
|
boolean |
consumeAll() |
abstract void |
content(T item)
Adds some content to this input stream.
|
void |
earlyEOF()
This method should be called to signal that an EOF has been
detected before all the expected content arrived.
|
void |
failed(Throwable x) |
protected abstract int |
get(T item,
byte[] buffer,
int offset,
int length)
Copies the given content into the given byte buffer.
|
long |
getContentRead() |
protected T |
getNextContent()
A convenience method to call nextContent and to check the return value, which if null then the
a check is made for EOF and the state changed accordingly.
|
void |
init(HttpChannelState state) |
boolean |
isAsync() |
boolean |
isEarlyEOF() |
boolean |
isEOF() |
boolean |
isFinished() |
boolean |
isReady() |
Object |
lock() |
void |
messageComplete()
This method should be called to signal that all the expected
content arrived.
|
protected abstract T |
nextContent()
Access the next content to be consumed from.
|
protected boolean |
onAsyncRead() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
recycle() |
protected abstract int |
remaining(T item) |
void |
run() |
void |
setReadListener(ReadListener readListener) |
protected void |
unready() |
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 HttpInput()
protected HttpInput(Object lock)
public void init(HttpChannelState state)
public final Object lock()
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 T getNextContent() throws IOException
IOException
nextContent()
protected abstract T nextContent() throws IOException
get(Object, byte[], int, int)
or consume(Object, int)
are required to consume data from the content.IOException
- if retrieving the content failsprotected abstract int remaining(T item)
item
- the contentprotected abstract int get(T item, byte[] buffer, int offset, int length)
item
- the content to copy frombuffer
- the buffer to copy intooffset
- the buffer offset to start copying fromlength
- the space available in the bufferprotected abstract void consume(T item, int length)
item
- the content to consumelength
- the number of bytes to consumeprotected abstract void blockForContent() throws IOException
IOException
- if the wait is interruptedpublic abstract void content(T item)
item
- the content to addprotected boolean onAsyncRead()
public long getContentRead()
public void earlyEOF()
public boolean isEarlyEOF()
public void messageComplete()
public boolean consumeAll()
public boolean isAsync()
public boolean isEOF()
public boolean isFinished()
isFinished
in class ServletInputStream
public boolean isReady()
isReady
in class ServletInputStream
protected void unready()
public void setReadListener(ReadListener readListener)
setReadListener
in class ServletInputStream
public void failed(Throwable x)
Copyright © 1995-2015 Webtide. All Rights Reserved.