Class HTTPMessageReader

java.lang.Object
  |
  +--HTTPMessageReader
Direct Known Subclasses:
HTTPRequestReader, HTTPResponseReader

public abstract class HTTPMessageReader
extends java.lang.Object

Stream reader for HTTP messages (requests and responses).


Field Summary
protected  java.util.ArrayList body
          The body of the message
protected  java.lang.String connection
          Header field: Connection
protected  int contentLength
          Header field: The length of message body
protected  java.util.ArrayList header
          The header of the message (blank line included)
protected  byte[] message
          The whole message obtained from the stream
protected  boolean mustCloseConnection
          Flag that informs whether the connection must be closed or not
protected  int offset
          Position of body in the message
(package private)  java.lang.String versionProtocol
          Start/Status line: The version of HTTP protocol, eg.
 
Constructor Summary
HTTPMessageReader()
           
 
Method Summary
private  void concatenateHeaderBody()
          Concatenates the header and the body in a whole message.
 void eraseCommand(java.lang.String cmd, int nbrParam)
          Erases from the header the line containing a command.
protected  void retrieveBody(java.io.DataInputStream distream)
          Receives the body of the message (if exists) from the stream.
protected  void retrieveHeader(java.io.DataInputStream distream)
          Reads inside the stream until the "\r\n" couple that separes header from body message.
static byte[] toArray(java.util.ArrayList arraylist)
          Converts an ArrayList of Bytes into an array of bytes.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

header

protected java.util.ArrayList header
The header of the message (blank line included)

body

protected java.util.ArrayList body
The body of the message

message

protected byte[] message
The whole message obtained from the stream

versionProtocol

java.lang.String versionProtocol
Start/Status line: The version of HTTP protocol, eg. HTTP/1.1

contentLength

protected int contentLength
Header field: The length of message body

offset

protected int offset
Position of body in the message

connection

protected java.lang.String connection
Header field: Connection

mustCloseConnection

protected boolean mustCloseConnection
Flag that informs whether the connection must be closed or not
Constructor Detail

HTTPMessageReader

public HTTPMessageReader()
Method Detail

retrieveHeader

protected void retrieveHeader(java.io.DataInputStream distream)
                       throws java.io.IOException
Reads inside the stream until the "\r\n" couple that separes header from body message.
Parameters:
distream - the stream of connection

retrieveBody

protected void retrieveBody(java.io.DataInputStream distream)
                     throws java.io.IOException
Receives the body of the message (if exists) from the stream.
Parameters:
distream - the stream of connection

concatenateHeaderBody

private void concatenateHeaderBody()
Concatenates the header and the body in a whole message.

toArray

public static byte[] toArray(java.util.ArrayList arraylist)
Converts an ArrayList of Bytes into an array of bytes.
Parameters:
arraylist - an ArrayList
Returns:
an array of bytes

eraseCommand

public void eraseCommand(java.lang.String cmd,
                         int nbrParam)
Erases from the header the line containing a command.
Parameters:
cmd - the command that identifies the line
nbrParam - the number of parameter to erase after the command cmd