Off by one when wrapping InputStream
See original GitHub issue
I use ProgressBar.wrap(InputStream, ProgressBarBuilder) where the stream is created by URL.openStream(). I set the initial max to the actual file size. Reducing the max by one (or even 10) has zero effect and will still show the actual file size (as if I set it to the correct size).
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
java - Effect on the original InputStream after wrapping with ...
This method need to wrap this InputStream with a BufferedInputStream to use its mark and reset functionality. However, the passed in InputStream ......
Read more >InputStream Wrapper that closes the stream once reading is ...
The general idea of a wrapper stream that closes the inner stream automatically once its end is reached is fine, but your implementation...
Read more >Streams - Learning Java, 4th Edition [Book] - O'Reilly
A method specifying an InputStream as an argument can accept any subclass of InputStream . Specialized types of streams can also be layered...
Read more >Java InputStream - Jenkov.com
Here is an example of wrapping a Java InputStream in a BufferedInputStream : InputStream input = new BufferedInputStream( new FileInputStream("c ...
Read more >InputStreamReader (Java Platform SE 7 ) - Oracle Help Center
Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, this is a bug. Here you do it correctly.
Looking at the code,
Util.getInputStreamSize()returns -1 for non-file streams (which I use) and that is used in the string constructor, but passing my own builder and leaving out the max initial it somehow detects it correctly.While the second constructor has a check for -1, the first will set the initial max regardless. This means that the first will have -1 while the second will have 0.
This all is only about the apparent inconsistency of the different behaviour in the different constructors. This still doesn’t explain the off by one.