T - The message-type (i.e. HttpRequest or HttpResponse).public abstract class HttpMessageChannel<T extends HttpMessage> extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
STATE_READING_BODY
After the header has been read, this constant defines the body-reading phase
|
static int |
STATE_READING_HEADER
This constant defines the state from the start until a complete message header has been read
|
| Modifier | Constructor and Description |
|---|---|
protected |
HttpMessageChannel(ReadableByteChannel inChannel)
This constructor creates a new instance of the message channel class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
This method closes the message-channel and also closes the
underlying byte-channel.
|
int |
getState()
This method returns the
int-code of the channel's
current state. |
Integer |
getTimeout()
This method returns the current timeout (in milliseconds) of the
channel.
|
ByteBuffer |
readBody(int contentLength)
This method reads the body of a HTTP message of the given length.
|
HttpHeader |
readHeader()
This method tries to read a HTTP message header from the currently
available bytes.
|
abstract T |
readMessage() |
void |
setTimeout(Integer to)
This method is used to set the timeout (in milliseconds) of the
channel.
|
boolean |
timedOut()
This method can be used to check if the channel is timed out or not.
|
void |
touch()
This method simply touches the channel an sets the time of the
last read to
System.currentTimeMillis(). |
public static final int STATE_READING_HEADER
public static final int STATE_READING_BODY
protected HttpMessageChannel(ReadableByteChannel inChannel)
inChannel - The byte-channel to read messages from.public HttpHeader readHeader() throws TimeOutException, IOException, ProtocolException
null is returned. The
method is re-entrant in the way, that a later invocation resumes
the previously header-read.null otherwise.TimeOutException - In case the channel timed out.IOException - If a read-error occurs.ProtocolException - In case the header could not be parsed or
the method is called in a wrong state (e.g. body-reading).public ByteBuffer readBody(int contentLength) throws IOException, TimeOutException, ProtocolException
contentLength - null if less than contentLength bytes
can be read without blocking.IOException - In case an I/O error occurred.TimeOutException - If this method is called after the channel timed out.ProtocolException - In case a parsing error occured (unlikely ;-) or the
method was called in an incorrect state (reading header state).public int getState()
int-code of the channel's
current state.public void close()
throws IOException
IOException - In case closing the underlying byte-channel
resulted in an I/O error.public Integer getTimeout()
public void setTimeout(Integer to)
to - The timeout (milliseconds).public boolean timedOut()
timeout
milliseconds ago, otherwise false.public void touch()
System.currentTimeMillis().public abstract T readMessage() throws TimeOutException, IOException, ProtocolException
Copyright © 2014 jwall.org. All Rights Reserved.