|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjuglr.net.HTTPReader
public class HTTPReader
base class for HTTPRequestReader
and HTTPResponseReader
Field Summary | |
---|---|
protected java.nio.ByteBuffer |
buf
|
protected java.nio.channels.SocketChannel |
channel
|
static int |
MAX_HEADER_LENGTH
|
Constructor Summary | |
---|---|
HTTPReader(java.nio.channels.SocketChannel channel,
java.nio.ByteBuffer buf)
|
Method Summary | |
---|---|
void |
close()
Close the underlying channel if it's open |
int |
readBody(byte[] target)
|
int |
readBody(byte[] target,
int offset,
int len)
|
int |
readHeaderField(byte[] target)
Read a HTTP header line (termincated by \r\n ) |
boolean |
readLF()
Read the next byte and and check if it is a carriage return - if it is then read the second byte and check if it's a newline - and if both bytes are good return true . |
boolean |
readSpace()
Read the next byte and return true if it is a white space |
HTTP.Status |
readStatus()
Read a numeric HTTP status code and return it as a HTTP.Status |
HTTP.Version |
readVersion()
Parse a HTTP protocol version declaration as used in the HTTP protocol. |
HTTPReader |
reset(java.nio.channels.SocketChannel channel)
Reset all state in the reader, preparing it for reading channel . |
java.io.InputStream |
streamBody()
Read the message body as a stream, starting from the current position. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAX_HEADER_LENGTH
protected java.nio.channels.SocketChannel channel
protected java.nio.ByteBuffer buf
Constructor Detail |
---|
public HTTPReader(java.nio.channels.SocketChannel channel, java.nio.ByteBuffer buf)
Method Detail |
---|
public void close() throws java.io.IOException
java.io.IOException
- if the underlying channel is open and there is an
error closing the channelpublic HTTPReader reset(java.nio.channels.SocketChannel channel) throws java.io.IOException
channel
.
channel
- the channel to start reading from. If the reader refers
a channel then this channel will be closed.
this
java.io.IOException
- if the reader already refers an open channel and
there is an error closing itpublic int readHeaderField(byte[] target)
\r\n
)
target
- the buffer to read data into
target
. If this is 0
then this was the last header before the body and you may
invoke readBody(byte[])
or streamBody()
public HTTP.Status readStatus() throws java.io.IOException
HTTP.Status
java.io.IOException
- upon errors reading from the socket
HTTP.UnsupportedStatusException
- if the server returns and uncommon
HTTP status code that is not supported
by Juglrpublic HTTP.Version readVersion() throws java.io.IOException
HTTP.Version.ERROR
on errors
java.io.IOException
- upon errors reading from the socketpublic boolean readSpace() throws java.io.IOException
true
if it is a white space
true
if the next byte is a space, false
otherwise
java.io.IOException
- upon errors reading from the socketpublic boolean readLF() throws java.io.IOException
true
.
true
if the next two bytes are \r
and \n
false
otherwise
java.io.IOException
- upon errors reading from the socketpublic int readBody(byte[] target) throws java.io.IOException
java.io.IOException
public int readBody(byte[] target, int offset, int len) throws java.io.IOException
java.io.IOException
public java.io.InputStream streamBody()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |