Package me.desair.tus.server.util
Class HttpChunkedEncodingInputStream
java.lang.Object
java.io.InputStream
me.desair.tus.server.util.HttpChunkedEncodingInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Transparently coalesces chunks of a HTTP stream that uses Transfer-Encoding chunked. This
Based on org.apache.commons.httpclient.ChunkedInputStream
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 Summary
ConstructorDescriptionWrap the given input stream.HttpChunkedEncodingInputStream
(InputStream in, Map<String, List<String>> trailerHeaders) Wrap the given input stream and store any trailing headers in the provided map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
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.int
read()
Reads the next byte of data from the input stream.int
read
(byte[] b) Read some bytes from the stream.int
read
(byte[] b, int off, int len) Read some bytes from the stream.Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
HttpChunkedEncodingInputStream
Wrap the given input stream and store any trailing headers in the provided map.- Parameters:
in
- the raw input streamtrailerHeaders
- Map to store any trailer header values. Can be null.
-
HttpChunkedEncodingInputStream
Wrap the given input stream. Do not store any trailing headers.- Parameters:
in
- the raw input stream
-
-
Method Details
-
read
Reads the next byte of data from the input stream. The value byte is returned as anint
in the range0
to255
.- Specified by:
read
in classInputStream
- Returns:
- -1 of the end of the stream has been reached or the next data byte
- Throws:
IOException
- If an IO problem occurs
-
read
Read some bytes from the stream.- Overrides:
read
in classInputStream
- 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
Read some bytes from the stream.- Overrides:
read
in classInputStream
- 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
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- If an IO problem occurs.
-