org.mortbay.jetty
Class HttpGenerator

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

public class HttpGenerator
extends Object
implements HttpTokens

HttpGenerator. Builds HTTP Messages.

Author:
gregw

Nested Class Summary
static class HttpGenerator.Output
          Output.
static class HttpGenerator.OutputWriter
          OutputWriter.
 
Field Summary
static boolean LAST
           
static boolean MORE
           
static int STATE_CONTENT
           
static int STATE_END
           
static int STATE_FLUSHING
           
static int STATE_HEADER
           
 
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.
 boolean addContent(byte b)
          Add content.
 void complete()
          Complete the message.
 void completeHeader(HttpFields fields, boolean allContentAdded)
           
 long flushBuffers()
           
 int getContentBufferSize()
           
 long getContentWritten()
           
static String getReason(int code)
           
 boolean getSendServerVersion()
           
 int getState()
           
 Buffer getUncheckedBuffer()
           
 void increaseContentBufferSize(int contentBufferSize)
           
 boolean isBufferFull()
           
 boolean isCommitted()
           
 boolean isComplete()
           
 boolean isHead()
           
 boolean isPersistent()
           
 boolean isState(int state)
           
 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 setSendServerVersion(boolean sendServerVersion)
           
static void setServerVersion(String version)
           
 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
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

setServerVersion

public static void setServerVersion(String version)

getReason

public static String getReason(int code)

reset

public void reset(boolean returnBuffers)

resetBuffer

public void resetBuffer()

getUncheckedBuffer

public Buffer getUncheckedBuffer()

getSendServerVersion

public boolean getSendServerVersion()

setSendServerVersion

public void setSendServerVersion(boolean sendServerVersion)

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:
false if the connection should be closed after a request has been read, true if it should be used for additional requests.

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 -
last -
Throws:
IllegalArgumentException - if content is immutable.
IllegalStateException - If the request is not expecting any more content, or if the buffers are full and cannot be flushed.
IOException - if there is a problem flushing the buffers.

addContent

public boolean addContent(byte b)
                   throws IOException
Add content.

Parameters:
b - byte
Returns:
true if the buffers are full
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 long flushBuffers()
                  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.