mmhttp.protocol
Class InputStreamResponse

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

public class InputStreamResponse
extends Response

A derivative of Response that is ideal for large data sets. For example, if you have a large file that you wish to transmit, using SimpleResponse would reqire that the entire file be loaded into memory. Instead, use InputStreamResponse and the data will be loaded and and transmitted in 1000 byte segments.


Field Summary
 
Fields inherited from class mmhttp.protocol.Response
CRLF, DEFAULT_CONTENT_TYPE
 
Constructor Summary
InputStreamResponse()
           
 
Method Summary
protected  void addSpecificHeaders()
           
 int getContentSize()
          A method to get the size of the response content.
 void readyToSend(ResponseSender sender)
          This initiated the transmition of data.
 void setBody(java.io.File file)
          A shorcut to send a file.
 void setBody(java.io.InputStream input, int size)
          Sets the body of the 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

InputStreamResponse

public InputStreamResponse()
Method Detail

readyToSend

public void readyToSend(ResponseSender sender)
                 throws java.lang.Exception
This initiated the transmition of data. Date will be read in 1000 bytes at a time and transmitted to the client.

Specified by:
readyToSend in class Response
Parameters:
sender -
Throws:
java.lang.Exception

addSpecificHeaders

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

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 of data to be transmitted, not including protocol overhead.

setBody

public void setBody(java.io.InputStream input,
                    int size)
Sets the body of the response. There is no efficient way to count the bytes in the stream prior to sending so it neccessary to provide an accurate count of bytes here.

Parameters:
input -
size - - number of bytes in the stream

setBody

public void setBody(java.io.File file)
             throws java.lang.Exception
A shorcut to send a file. An InputStream will be created from the specified file.

Parameters:
file -
Throws:
java.lang.Exception


Copyright © 2009 Micah Martin. All Rights Reserved.