org.mortbay.jetty
Class HttpGenerator

java.lang.Object
  extended by org.mortbay.jetty.HttpGenerator
All Implemented Interfaces:
HttpTokens

public class HttpGenerator
extends Object
implements HttpTokens

HttpGenerator. Builds HTTP Messages.

Author:
gregw

Field Summary
private static String[] __reasons
           
private  Buffer _buffer
           
private  boolean _bufferChunked
           
private  Buffers _buffers
           
private  boolean _close
           
private  Buffer _content
           
private  int _contentBufferSize
           
private  long _contentLength
           
private  long _contentWritten
           
(package private)  boolean _direct
           
private  EndPoint _endp
           
private  boolean _head
           
private  Buffer _header
           
private  int _headerBufferSize
           
private  boolean _last
           
private  boolean _needCRLF
           
private  boolean _needEOC
           
private  String _reason
           
private  int _state
           
private  int _status
           
private  int _version
           
private static int CHUNK_SPACE
           
private static byte[] CONNECTION_CLOSE
           
private static byte[] CONNECTION_KEEP_ALIVE
           
private static byte[] CONTENT_LENGTH_0
           
static boolean LAST
           
private static byte[] LAST_CHUNK
           
static boolean MORE
           
private static byte[] SERVER
           
static int STATE_CONTENT
           
static int STATE_END
           
static int STATE_FLUSHING
           
static int STATE_HEADER
           
private static byte[] TRANSFER_ENCODING_CHUNKED
           
 
Fields inherited from interface org.mortbay.jetty.HttpTokens
CARRIAGE_RETURN, CHUNKED_CONTENT, COLON, CRLF, EOF_CONTENT, LINE_FEED, NO_CONTENT, SELF_DEFINING_CONTENT, SEMI_COLON, SPACE, TAB, UNKNOWN_CONTENT
 
Constructor Summary
HttpGenerator(Buffers buffers, EndPoint io, int headerBufferSize, int contentBufferSize)
          Constructor.
 
Method Summary
 void addContent(Buffer content, boolean last)
          Add _content.
 void complete()
          Complete the message.
 void completeHeader(HttpFields fields, boolean allContentAdded)
           
 void flushBuffers()
           
 long getContentAdded()
           
 int getContentBufferSize()
           
 long getContentWritten()
           
static String getReason(int code)
           
 int getState()
           
 void increaseContentBufferSize(int contentBufferSize)
           
 boolean isBufferFull()
           
 boolean isCommitted()
           
 boolean isComplete()
           
 boolean isHead()
           
 boolean isPersistent()
           
 boolean isState(int state)
           
private  void prepareBuffers()
           
 void reset(boolean returnBuffers)
           
 void resetBuffer()
           
 void sendError(int code, String reason, String content, boolean close)
          Utility method to send an error response.
 void setHead(boolean head)
           
 void setRequest(Buffer method, Buffer uri)
           
 void setResponse(int status, String reason)
           
 void setVersion(int version)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_HEADER

public static final int STATE_HEADER
See Also:
Constant Field Values

STATE_CONTENT

public static final int STATE_CONTENT
See Also:
Constant Field Values

STATE_FLUSHING

public static final int STATE_FLUSHING
See Also:
Constant Field Values

STATE_END

public static final int STATE_END
See Also:
Constant Field Values

LAST

public static final boolean LAST
See Also:
Constant Field Values

MORE

public static final boolean MORE
See Also:
Constant Field Values

LAST_CHUNK

private static byte[] LAST_CHUNK

CONTENT_LENGTH_0

private static byte[] CONTENT_LENGTH_0

CONNECTION_KEEP_ALIVE

private static byte[] CONNECTION_KEEP_ALIVE

CONNECTION_CLOSE

private static byte[] CONNECTION_CLOSE

TRANSFER_ENCODING_CHUNKED

private static byte[] TRANSFER_ENCODING_CHUNKED

SERVER

private static byte[] SERVER

CHUNK_SPACE

private static int CHUNK_SPACE

__reasons

private static String[] __reasons

_state

private int _state

_version

private int _version

_status

private int _status

_reason

private String _reason

_contentWritten

private long _contentWritten

_contentLength

private long _contentLength

_last

private boolean _last

_head

private boolean _head

_close

private boolean _close

_buffers

private Buffers _buffers

_endp

private EndPoint _endp

_header

private Buffer _header

_buffer

private Buffer _buffer

_content

private Buffer _content

_direct

boolean _direct

_needCRLF

private boolean _needCRLF

_needEOC

private boolean _needEOC

_bufferChunked

private boolean _bufferChunked

_headerBufferSize

private int _headerBufferSize

_contentBufferSize

private int _contentBufferSize
Constructor Detail

HttpGenerator

public HttpGenerator(Buffers buffers,
                     EndPoint io,
                     int headerBufferSize,
                     int contentBufferSize)
Constructor.

Parameters:
buffers - buffer pool
headerBufferSize - Size of the buffer to allocate for HTTP header
contentBufferSize - Size of the buffer to allocate for HTTP content
Method Detail

getReason

public static String getReason(int code)

reset

public void reset(boolean returnBuffers)

resetBuffer

public void resetBuffer()

getState

public int getState()

isState

public boolean isState(int state)

isComplete

public boolean isComplete()

isCommitted

public boolean isCommitted()

isHead

public boolean isHead()
Returns:
Returns the head.

setHead

public void setHead(boolean head)
Parameters:
head - The head to set.

isPersistent

public boolean isPersistent()
Returns:

getContentAdded

public long getContentAdded()

setVersion

public void setVersion(int version)
Parameters:
version - The version of the client the response is being sent to (NB. Not the version in the response, which is the version of the server).

setRequest

public void setRequest(Buffer method,
                       Buffer uri)

setResponse

public void setResponse(int status,
                        String reason)
Parameters:
status - The status code to send.
reason - the status message to send.

addContent

public void addContent(Buffer content,
                       boolean last)
                throws IOException
Add _content.

Parameters:
_content -
Throws:
IOException

isBufferFull

public boolean isBufferFull()

completeHeader

public void completeHeader(HttpFields fields,
                           boolean allContentAdded)
                    throws IOException
Throws:
IOException

complete

public void complete()
              throws IOException
Complete the message.

Throws:
IOException

flushBuffers

public void flushBuffers()
                  throws IOException
Throws:
IOException

prepareBuffers

private void prepareBuffers()
                     throws IOException
Throws:
IOException

sendError

public void sendError(int code,
                      String reason,
                      String content,
                      boolean close)
               throws IOException
Utility method to send an error response. If the builder is not committed, this call is equivalent to a setResponse, addcontent and complete call.

Parameters:
code -
reason -
_content -
close -
Throws:
IOException

getContentBufferSize

public int getContentBufferSize()
Returns:
Returns the contentBufferSize.

increaseContentBufferSize

public void increaseContentBufferSize(int contentBufferSize)
Parameters:
contentBufferSize - The contentBufferSize to set.

getContentWritten

public long getContentWritten()
Returns:
Returns the contentWritten.