Class HttpChunkedEncodingInputStream

java.lang.Object
java.io.InputStream
me.desair.tus.server.util.HttpChunkedEncodingInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class HttpChunkedEncodingInputStream extends InputStream
Transparently coalesces chunks of a HTTP stream that uses Transfer-Encoding chunked. This InputStream wrapper also supports collecting Trailer header values that are sent at the end of the stream.
Based on org.apache.commons.httpclient.ChunkedInputStream
  • Constructor Details

    • HttpChunkedEncodingInputStream

      public HttpChunkedEncodingInputStream(InputStream in, Map<String,List<String>> trailerHeaders)
      Wrap the given input stream and store any trailing headers in the provided map.
      Parameters:
      in - the raw input stream
      trailerHeaders - Map to store any trailer header values. Can be null.
    • HttpChunkedEncodingInputStream

      public HttpChunkedEncodingInputStream(InputStream in)
      Wrap the given input stream. Do not store any trailing headers.
      Parameters:
      in - the raw input stream
  • Method Details

    • read

      public int read() throws IOException
      Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255.
      Specified by:
      read in class InputStream
      Returns:
      -1 of the end of the stream has been reached or the next data byte
      Throws:
      IOException - If an IO problem occurs
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Read some bytes from the stream.
      Overrides:
      read in class InputStream
      Parameters:
      b - The byte array that will hold the contents from the stream.
      off - The offset into the byte array at which bytes will start to be placed.
      len - the maximum number of bytes that can be returned.
      Returns:
      The number of bytes returned or -1 if the end of stream has been reached.
      Throws:
      IOException - if an IO problem occurs.
      See Also:
    • read

      public int read(byte[] b) throws IOException
      Read some bytes from the stream.
      Overrides:
      read in class InputStream
      Parameters:
      b - The byte array that will hold the contents from the stream.
      Returns:
      The number of bytes returned or -1 if the end of stream has been reached.
      Throws:
      IOException - if an IO problem occurs.
      See Also:
    • close

      public void close() throws IOException
      Upon close, this reads the remainder of the chunked message, leaving the underlying socket at a position to start reading the next response without scanning.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException - If an IO problem occurs.