Package ej.hoka.io

Class ChunkedMessageBodyInputStream

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

    public class ChunkedMessageBodyInputStream
    extends java.io.InputStream
    Input Stream for reading HTTP 1.1 Chunked transfer encoding data.

    Each chunk starts with the number of octets of the data it embeds, expressed as a hexadecimal number in ASCII, followed by optional parameters (chunk extension) and a terminating CRLF sequence, followed by the chunk data. The chunk is terminated by CRLF. If chunk extensions are provided, the chunk size is terminated by a semicolon followed with the extension name and an optional equal sign and value. (chunk extensions are skipped).

    • Constructor Summary

      Constructors 
      Constructor Description
      ChunkedMessageBodyInputStream​(java.io.InputStream is)
      Creates a new ChunkedMessageBodyInputStream using the InputStream is as the underlying data source.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      Returns the number of available bytes to read.
      void close()
      Reads all remaining message body data and closes this input stream.
      int read()
      Reads the next byte from the InputStream used in the constructor.
      int read​(byte[] data, int offset, int length)
      Reads up to length bytes to the byte array data starting with offset.
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • ChunkedMessageBodyInputStream

        public ChunkedMessageBodyInputStream​(java.io.InputStream is)
        Creates a new ChunkedMessageBodyInputStream using the InputStream is as the underlying data source.
        Parameters:
        is - InputStream to read from.
    • Method Detail

      • available

        public int available()
                      throws java.io.IOException
        Returns the number of available bytes to read.
        Overrides:
        available in class java.io.InputStream
        Returns:
        the number of available bytes to read.
        Throws:
        java.io.IOException - if the ChunkedMessageBodyInputStream is already closed.
      • close

        public void close()
                   throws java.io.IOException
        Reads all remaining message body data and closes this input 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.InputStream
        Throws:
        java.io.IOException - when an error occurs while closing the stream
      • read

        public int read()
                 throws java.io.IOException
        Reads the next byte from the InputStream used in the constructor.
        Specified by:
        read in class java.io.InputStream
        Returns:
        the next byte value (0-255) or -1 if the end of the InputStream has been reached.
        Throws:
        java.io.IOException - when the InputStream has already been closed.
      • read

        public int read​(byte[] data,
                        int offset,
                        int length)
                 throws java.io.IOException
        Reads up to length bytes to the byte array data starting with offset. The method tries to read length bytes (if there are at least length bytes in the InputStream used in the constructor. Otherwise reads just the available number of bytes).
        Overrides:
        read in class java.io.InputStream
        Parameters:
        data - the byte array to store the bytes read from the underlying InputStream
        offset - the position in the byte array data to store the bytes read from the InputStream.
        length - number of bytes to store in the byte array data (if the number of bytes available in the InputStream are at least length ) If less than length bytes are left in the InputStream, only the remaining bytes are stored in the byte array data.
        Returns:
        the number of bytes stored in the byte array data, or -1 if no bytes can be stored in the byte array data.
        Throws:
        java.io.IOException - when the end of InputStream has already been reached.