mmhttp.protocol
Class ChunkedResponse

java.lang.Object
  extended by mmhttp.protocol.Response
      extended by mmhttp.protocol.ChunkedResponse

public class ChunkedResponse
extends Response

This a special type of Response that supports HTTP 1.1 Chunking. A snippet from the HTTP 1.1 RFC:

 The chunked encoding modifies the body of a message in
 order to transfer it as a series of chunks, each with its
 own size indicator, followed by an OPTIONAL trailer
 containing entity-header fields. This allows dynamically
 produced content to be transferred along with the
 information necessary for the recipient to verify that it
 has received the full message.
 


Field Summary
 
Fields inherited from class mmhttp.protocol.Response
CRLF, DEFAULT_CONTENT_TYPE
 
Constructor Summary
ChunkedResponse()
           
 
Method Summary
 void add(byte[] bytes)
          Sends a chunk of data to the client.
 void add(java.lang.String text)
          Sends a chunk of text to the client.
protected  void addSpecificHeaders()
           
 void addTrailingHeader(java.lang.String key, java.lang.String value)
          Trailing headers are sent to the client after all the chunks have been delievered.
 void close()
          Call this method to conclude the response.
 void closeAll()
          This is a short cut to be used if there are not traling headers.
 void closeChunks()
          Call this method when you are through sending all the chunks.
 void closeTrailer()
          Call this method when you're finished sending trailing headers.
 int getContentSize()
          A method to get the size of the response content.
 boolean isReadyToSend()
           
 void readyToSend(ResponseSender sender)
          Begins the transfer of the HTTP response.
 
Methods inherited from class mmhttp.protocol.Response
addHeader, addStandardHeaders, getContentType, getEncodedBytes, getHeader, getReasonPhrase, getReasonPhrase, getStatus, makeHttpHeaders, makeStandardHttpDateFormat, redirect, setContentType, setExpiresHeader, setLastModifiedHeader, setMaxAge, setStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChunkedResponse

public ChunkedResponse()
Method Detail

readyToSend

public void readyToSend(ResponseSender sender)
                 throws java.lang.Exception
Begins the transfer of the HTTP response. The standard HTTP headers will be delievered upon calling this method.

Specified by:
readyToSend in class Response
Parameters:
sender - is responsible for transmitting the data
Throws:
java.lang.Exception

isReadyToSend

public boolean isReadyToSend()
Returns:
true if the response is accepting data to be transmitted.

addSpecificHeaders

protected void addSpecificHeaders()
Specified by:
addSpecificHeaders in class Response

add

public void add(java.lang.String text)
         throws java.lang.Exception
Sends a chunk of text to the client. The string will be converted to bytes prior to transfer.

Parameters:
text -
Throws:
java.lang.Exception

add

public void add(byte[] bytes)
         throws java.lang.Exception
Sends a chunk of data to the client.

Parameters:
bytes -
Throws:
java.lang.Exception

addTrailingHeader

public void addTrailingHeader(java.lang.String key,
                              java.lang.String value)
                       throws java.lang.Exception
Trailing headers are sent to the client after all the chunks have been delievered. This method does not enforce this requirement so you must make sure not to use this methon until after calling closeChunks().

Parameters:
key -
value -
Throws:
java.lang.Exception
See Also:
closeChunks()

closeChunks

public void closeChunks()
                 throws java.lang.Exception
Call this method when you are through sending all the chunks.

Throws:
java.lang.Exception

closeTrailer

public void closeTrailer()
                  throws java.lang.Exception
Call this method when you're finished sending trailing headers.

Throws:
java.lang.Exception
See Also:
addTrailingHeader(java.lang.String, java.lang.String)

close

public void close()
           throws java.lang.Exception
Call this method to conclude the response.

Throws:
java.lang.Exception

closeAll

public void closeAll()
              throws java.lang.Exception
This is a short cut to be used if there are not traling headers. Call it when you are through sending chunks.

Throws:
java.lang.Exception

getContentSize

public int getContentSize()
Description copied from class: Response
A method to get the size of the response content. Abstract because, who know how the response is built?

Specified by:
getContentSize in class Response
Returns:
the number of bytes sent as chunks. It is the amount of pure data transfered not including all the protocol overhead.


Copyright © 2009 Micah Martin. All Rights Reserved.