Package ej.hoka.io

Class ChunkedMessageBodyOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class ChunkedMessageBodyOutputStream
    extends java.io.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 Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close this output stream.
      void flush()
      Writes the pending data and flush underlying stream.
      void write​(byte[] b, int off, int len)
      Writes the content of the byte array b from the offset off in length len in chunked encoding using the underlying OutputStream.
      void write​(int b)
      Write one byte of data.
      • Methods inherited from class java.io.OutputStream

        nullOutputStream, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ChunkedMessageBodyOutputStream

        public ChunkedMessageBodyOutputStream​(java.io.OutputStream os)
        Creates a new instance of ChunkedMessageBodyOutputStream using the specified OutputStream as the underlying OutputStream.
        Parameters:
        os - the underlying OutputStream to use
    • Method Detail

      • close

        public final void close()
                         throws java.io.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 java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException - when an error occurs while closing the stream
      • flush

        public final void flush()
                         throws java.io.IOException
        Writes the pending data and flush underlying stream.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException - when the connection is closed.
      • write

        public final void write​(byte[] b,
                                int off,
                                int len)
                         throws java.io.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 java.io.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:
        java.io.IOException - if the ChunkedMessageBodyOutputStream is already closed.
      • write

        public final void write​(int b)
                         throws java.io.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 java.io.OutputStream
        Parameters:
        b - the byte to write to the underlying OutputStream
        Throws:
        java.io.IOException - if the ChunkedMessageBodyOutputStream is already closed.
        See Also:
        OutputStream.write(int)