Class sun.server.http.ChunkedOutputStream
All Packages Class Hierarchy This Package Previous Next Index
Class sun.server.http.ChunkedOutputStream
java.lang.Object
|
+----java.io.OutputStream
|
+----java.io.FilterOutputStream
|
+----java.io.BufferedOutputStream
|
+----sun.server.http.ChunkedOutputStream
- public class ChunkedOutputStream
- extends BufferedOutputStream
An OutputStream that implements HTTP/1.1 chunking.
This class lets a Servlet send its response data as an HTTP/1.1 chunked
stream. Chunked streams are a way to send arbitrary-length data without
having to know beforehand how much you're going to send. They are
introduced by a "Transfer-Encoding: chunked" header, so you have to
set that header when you make one of these streams.
Sample usage:
res.setHeader( "Transfer-Encoding", "chunked" );
OutputStream out = res.getOutputStream();
ChunkedOutputStream chunkOut = new ChunkedOutputStream( out );
(write data to chunkOut instead of out)
(optionally set footers)
chunkOut.done();
Every time the stream gets flushed, a chunk is sent. When done()
is called, an empty chunk is sent, marking the end of the chunked
stream as per the chunking spec.
-
ChunkedOutputStream(OutputStream)
- Make a ChunkedOutputStream with a default buffer size.
-
ChunkedOutputStream(OutputStream, int)
- Make a ChunkedOutputStream with a specified buffer size.
-
close()
- Make sure that calling close() terminates the chunked stream.
-
done()
- Indicate the end of the chunked data by sending a zero-length chunk,
possible including footers.
-
flush()
- Flush the stream.
-
reset(OutputStream)
- Reset the stream for a new connection.
-
setFooter(String, String)
- Set a footer.
-
write(byte[], int, int)
- Write a sub-array of bytes.
ChunkedOutputStream
public ChunkedOutputStream(OutputStream out)
- Make a ChunkedOutputStream with a default buffer size.
- Parameters:
- out - the underlying output stream
ChunkedOutputStream
public ChunkedOutputStream(OutputStream out,
int size)
- Make a ChunkedOutputStream with a specified buffer size.
- Parameters:
- out - the underlying output stream
- size - the buffer size
reset
public void reset(OutputStream out)
- Reset the stream for a new connection.
flush
public synchronized void flush() throws IOException
- Flush the stream. This will write any buffered output
bytes as a chunk.
- Throws: IOException
- if an I/O error occurred
- Overrides:
- flush in class BufferedOutputStream
setFooter
public void setFooter(String name,
String value)
- Set a footer. Footers are much like HTTP headers, except that
they come at the end of the data instead of at the beginning.
done
public void done() throws IOException
- Indicate the end of the chunked data by sending a zero-length chunk,
possible including footers.
- Throws: IOException
- if an I/O error occurred
close
public void close() throws IOException
- Make sure that calling close() terminates the chunked stream.
- Overrides:
- close in class FilterOutputStream
write
public synchronized void write(byte b[],
int off,
int len) throws IOException
- Write a sub-array of bytes.
The only reason we have to override the BufferedOutputStream version
of this is that it writes the array directly to the output stream
if doesn't fit in the buffer. So we make it use our own chunk-write
routine instead. Otherwise this is identical to the parent-class
version.
- Parameters:
- b - the data to be written
- off - the start offset in the data
- len - the number of bytes that are written
- Throws: IOException
- if an I/O error occurred
- Overrides:
- write in class BufferedOutputStream
All Packages Class Hierarchy This Package Previous Next Index