CADI.Server.Network
Class HTTPResponseSender

java.lang.Object
  extended by CADI.Server.Network.HTTPResponseSender

public class HTTPResponseSender
extends java.lang.Object

This class implements a wrapper to send an HTTP Response.

Version:
1.0.1 2008/05/01
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  boolean chunkedMode
          Not used yet.
private static java.lang.String CRLF
          Is the carriage-return and line-feed characters.
static byte[] CRLF_Bytes
          Is the carriage and return line-feed bytes.
private static java.lang.String HTTP_VERSION_11
           
private  float maxTxRate
          Definition in Scheduler.maxTxRate.
private  java.io.OutputStream os
          Is an output stream that will be used to send the server response to the client.
private  long[] sentBytes
           
private  long[] times
           
 
Constructor Summary
HTTPResponseSender(java.io.OutputStream os)
          Constructor.
 
Method Summary
 void endOfChunk()
          Sends the end of the chunk.
 void endOfHeaders()
           
 void flush()
          Flushes this output stream and forces any buffered output bytes to be sent.
 void sendChunk(byte[] chunk)
          Sends a chunk of the HTTP body.
 void sendChunks(byte[]... args)
          Sends multiple chunks as a only one chunk.
 void sendHeader(java.lang.String header)
           
 void sendHeader(java.lang.String key, java.lang.String value)
           
 void sendHeaders(HTTPResponse headers)
          Sends the HTTP protocol's headers.
 void sendHeaders(java.lang.String... args)
           
 void setMaxTxRate(float maxTxRate)
          Sets the maxTxRate attribute.
private  void updateBytesSentAndTimes(long bytes, long time)
          This method updates the #bytesSent and times attributes with new new values which are parssed as input parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CRLF

private static final java.lang.String CRLF
Is the carriage-return and line-feed characters.

See Also:
Constant Field Values

CRLF_Bytes

public static final byte[] CRLF_Bytes
Is the carriage and return line-feed bytes.


os

private java.io.OutputStream os
Is an output stream that will be used to send the server response to the client.


maxTxRate

private float maxTxRate
Definition in Scheduler.maxTxRate. But a O value does not mean unlimited rate delivery, it means to delivery at 0 bytes/sec.


HTTP_VERSION_11

private static final java.lang.String HTTP_VERSION_11
See Also:
Constant Field Values

chunkedMode

private boolean chunkedMode
Not used yet.


sentBytes

private long[] sentBytes

times

private long[] times
Constructor Detail

HTTPResponseSender

public HTTPResponseSender(java.io.OutputStream os)
Constructor.

Parameters:
os - the output stream to send the HTTP data.
Throws:
java.lang.NullPointerException - if the output stream parameter is null.
Method Detail

setMaxTxRate

public final void setMaxTxRate(float maxTxRate)
Sets the maxTxRate attribute.

Parameters:
maxTxRate - definition in maxTxRate.

sendHeaders

public void sendHeaders(HTTPResponse headers)
                 throws java.io.IOException
Sends the HTTP protocol's headers. Headers must be passed as a HTTPResponse object.

Parameters:
headers - the HTTP protocol's header to send.
Throws:
java.io.IOException - if there is not connection to the remote host or the operation has been interrupted.

sendHeaders

public void sendHeaders(java.lang.String... args)
                 throws java.io.IOException
Parameters:
args -
Throws:
java.io.IOException

sendHeader

public void sendHeader(java.lang.String header)
                throws java.io.IOException
Parameters:
header -
Throws:
java.io.IOException - if there is not connection to the remote host or the operation has been interrupted.

sendHeader

public void sendHeader(java.lang.String key,
                       java.lang.String value)
                throws java.io.IOException
Parameters:
key -
value -
Throws:
java.io.IOException - if there is not connection to the remote host or the operation has been interrupted.

endOfHeaders

public void endOfHeaders()
                  throws java.io.IOException
Throws:
java.io.IOException - if there is not connection to the remote host or the operation has been interrupted.

sendChunk

public void sendChunk(byte[] chunk)
               throws java.io.IOException
Sends a chunk of the HTTP body. If the chunk data is null, this method returns and does nothing.

This method is only used when the HTTP chunked mode mode is set.

Parameters:
chunk - a byte array with chunk data to send.
Throws:
java.io.IOException - if there is not connection to the remote host or the operation has been interrupted.

sendChunks

public void sendChunks(byte[]... args)
                throws java.io.IOException
Sends multiple chunks as a only one chunk. The sent chunk length is the total amount of all chunk parameters. If some of the chunk parameter is null, it is discarded.

This method is only used when the HTTP chunked mode mode is set.

Parameters:
args - the chunk data
Throws:
java.io.IOException - if there is not connection to the remote host or the operation has been interrupted.

flush

public void flush()
           throws java.io.IOException
Flushes this output stream and forces any buffered output bytes to be sent.

Throws:
java.io.IOException - if there is not connection to the remote host or the operation has been interrupted.

endOfChunk

public void endOfChunk()
                throws java.io.IOException
Sends the end of the chunk. The end of the chunk consists of: 0
CRLF
CRLF

Throws:
java.io.IOException - if there is not connection to the remote host or the operation has been interrupted.

updateBytesSentAndTimes

private void updateBytesSentAndTimes(long bytes,
                                     long time)
This method updates the #bytesSent and times attributes with new new values which are parssed as input parameters.

Parameters:
bytes - the new value to be added in the #bytesSent attribute.
time - the new value to be added in the times attribute.


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)