hpack
hpack copied to clipboard
Decoder: use of available() call means many InputStream implementations are not supported
Describe the bug
https://github.com/twitter/hpack/blob/713612a439aa8f9b22cf4840054f9e7b3a787c02/hpack/src/main/java/com/twitter/hpack/Decoder.java#L92
https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html#available--
If you read the javadoc for available()
, you will see that it is only an estimate of the number of bytes that can be read without blocking. It does not relate to the number of remaining bytes in the stream and available=0 cannot be assumed to mean you have reached the end of the stream.
To Reproduce
I found this by using a SequenceInputStream. It can return 0 when you consume one of the underlying streams but before the SequenceInputStream switches over to the next underlying stream.
Expected behavior Decoder should read any InputStream to completion.