public static class HTTPServer.ChunkedOutputStream extends FilterOutputStream
ChunkedOutputStream encodes an OutputStream with the
"chunked" transfer encoding. It should be used only when the content
length is not known in advance, and with the response Transfer-Encoding
header set to "chunked".
Data is written to the stream by calling the write(byte[], int, int)
method, which writes a new chunk per invocation. To end the stream,
the writeTrailingChunk(org.noear.solon.boot.jlhttp.HTTPServer.Headers) method must be called or the stream closed.
| 限定符和类型 | 字段和说明 |
|---|---|
protected int |
state |
out| 构造器和说明 |
|---|
ChunkedOutputStream(OutputStream out)
Constructs a ChunkedOutputStream with the given underlying stream.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close()
Writes the trailing chunk if necessary, and closes the underlying stream.
|
protected void |
initChunk(long size)
Initializes a new chunk with the given size.
|
void |
write(byte[] b,
int off,
int len)
Writes a chunk containing the given bytes.
|
void |
write(int b)
Writes a chunk containing the given byte.
|
void |
writeTrailingChunk(HTTPServer.Headers headers)
Writes the trailing chunk which marks the end of the stream.
|
flush, writepublic ChunkedOutputStream(OutputStream out)
out - the underlying output stream to which the chunked stream
is writtenNullPointerException - if the given stream is nullprotected void initChunk(long size)
throws IOException
size - the chunk size (must be positive)IllegalArgumentException - if size is negativeIOException - if an IO error occurs, or the stream has
already been endedpublic void writeTrailingChunk(HTTPServer.Headers headers) throws IOException
headers - the (optional) trailing headers to write, or nullIOException - if an error occurspublic void write(int b)
throws IOException
write 在类中 FilterOutputStreamb - the byte to write as a chunkIOException - if an error occurspublic void write(byte[] b,
int off,
int len)
throws IOException
write 在类中 FilterOutputStreamb - an array containing the bytes to writeoff - the offset within the array where the data startslen - the length of the data in bytesIOException - if an error occursIndexOutOfBoundsException - if the given offset or length
are outside the bounds of the given arraypublic void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableclose 在类中 FilterOutputStreamIOException - if an error occursCopyright © 2021. All rights reserved.