Package ej.hoka.io

Class ChunkedMessageBodyOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    public class ChunkedMessageBodyOutputStream
    extends OutputStream
    Output Stream for writing HTTP 1.1 Chunked transfer encoding data.

    Each chunk starts with the number of octets of the data it embeds, expressed as a hexadecimal numbers in ASCII and a terminating CRLF sequence, followed by the chunk data. The chunk is terminated by CRLF.

    • Method Detail

      • close

        public final void close()
                         throws IOException
        Close this output stream. This method DOES NOT close the underlying stream (i.e. the TCP connection stream). It is the responsibility of the HTTPSession to close the underlying stream.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Overrides:
        close in class OutputStream
        Throws:
        IOException - when an error occurs while closing the stream
      • write

        public final void write​(byte[] b,
                                int off,
                                int len)
                         throws IOException
        Writes the content of the byte array b from the offset off in length len in chunked encoding using the underlying OutputStream.
        Overrides:
        write in class OutputStream
        Parameters:
        b - the byte array
        off - the starting index in byte array b
        len - the number of bytes written to the underlying Output stream in chunked encoding.
        Throws:
        IOException - if the ChunkedMessageBodyOutputStream is already closed.
      • write

        public final void write​(int b)
                         throws IOException
        Write one byte of data. The byte is not sent immediately, it is stored in a buffer and will be sent in a chunk when the buffer is full.
        Specified by:
        write in class OutputStream
        Parameters:
        b - the byte to write to the underlying OutputStream
        Throws:
        IOException - if the ChunkedMessageBodyOutputStream is already closed.
        See Also:
        OutputStream.write(int)