RFR: 8259956: jdk.jfr.internal.ChunkInputStream#available should return the sum of remaining available bytes

Denghui Dong ddong at openjdk.java.net
Mon Feb 1 09:32:47 UTC 2021


On Mon, 1 Feb 2021 08:47:10 GMT, Erik Gahlin <egahlin at openjdk.org> wrote:

> Not sure things should be changed. Javadoc for Inputstream::available() says:
> 
> "Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream."
> 
> How often the stream will block depends on the underlying BufferInputStream, so it seems correct to just delegate. Purpose of the available() method is not to return the total.

In my humble opinion, Most users always expect this method to return the total readable size, and this is achievable for this method, although the java doc does not force the implementer to do so,
it's meaningless if this method just returns the size of the current stream which is invisible to users, based on this return value, the user can hardly do anything.
On the contrary, if the total size can be returned, the user can do further operations based on this data, such as selecting an appropriate compression algorithm or discarding, etc. (Of course this is just my idea)

what do you think?

-------------

PR: https://git.openjdk.java.net/jdk/pull/2138


More information about the hotspot-jfr-dev mailing list