public class HTTPResponseSender
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
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 long |
maxChunkLength |
private long |
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 |
private TrafficShaping |
trafficShaping |
Constructor and Description |
---|
HTTPResponseSender(java.io.OutputStream os)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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 |
sendChunk(byte[] chunk,
int off,
int len)
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(long maxTxRate)
Sets the
maxTxRate attribute. |
void |
setMaxTxRate(long maxTxRate,
int algorithm) |
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. |
private static final java.lang.String CRLF
public static final byte[] CRLF_Bytes
private java.io.OutputStream os
private long maxTxRate
Scheduler.maxTxRate
. But a O
value does not mean unlimited rate delivery, it means to delivery at
0 bytes/sec.private static final java.lang.String HTTP_VERSION_11
private boolean chunkedMode
private long[] sentBytes
private long[] times
private TrafficShaping trafficShaping
private long maxChunkLength
public HTTPResponseSender(java.io.OutputStream os)
os
- the output stream to send the HTTP data.java.lang.NullPointerException
- if the output stream parameter is null.public final void setMaxTxRate(long maxTxRate)
maxTxRate
attribute.maxTxRate
- definition in maxTxRate
.public final void setMaxTxRate(long maxTxRate, int algorithm)
maxTxRate
- algorithm
- public void sendHeaders(HTTPResponse headers) throws java.io.IOException
headers
- the HTTP protocol's header to send.java.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.public void sendHeaders(java.lang.String... args) throws java.io.IOException
args
- java.io.IOException
public void sendHeader(java.lang.String header) throws java.io.IOException
header
- java.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.public void sendHeader(java.lang.String key, java.lang.String value) throws java.io.IOException
key
- value
- java.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.public void endOfHeaders() throws java.io.IOException
java.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.public void sendChunk(byte[] chunk) throws java.io.IOException
chunk data is
null
, this method returns and does nothing.
This method is only used when the HTTP chunked mode mode is set.
chunk
- a byte array with chunk data to send.java.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.public void sendChunk(byte[] chunk, int off, int len) throws java.io.IOException
chunk data is
null
, this method returns and does nothing.
This method is only used when the HTTP chunked mode mode is set.
chunk
- a byte array with chunk data to send.off
- offset of the first byte to be sent.len
- length of data to be sent.java.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.public void sendChunks(byte[]... args) throws java.io.IOException
chunk
parameter is null
, it is discarded.
This method is only used when the HTTP chunked mode mode is set.
args
- the chunk datajava.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.public void flush() throws java.io.IOException
java.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.public void endOfChunk() throws java.io.IOException
java.io.IOException
- if there is not connection to the remote host or the
operation has been interrupted.private void updateBytesSentAndTimes(long bytes, long time)
#bytesSent
and times
attributes
with new new values which are parssed as input 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)