-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Off by one when wrapping InputStream #60
Comments
Just to confirm -- you mean that you want to override the default size (as computed by the underlying stream) to a customized size using Why do you want to do this? I assume that the underlying actual file size is the size of the progress bar you want? |
Just checked, when using the |
Looking at the code, 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. |
OK! I got it. When reading the stream, I read until OEF by: while (in.read(buffer, 0, buffer.length) > -1) {
// do something.
} This causes stepBy to step back by one on EOF. |
So it is still a bug, right? |
This surprises me -- if it is not a |
Yes, this is a bug. Here you do it correctly. |
Ok, so downloading with a small delay reveals why this is happening. Not that it detects the file size, it just downloaded so fast that I couldn't see it. This line of code shows us that the max increases as the download proceeds but of-course won't backtrack when the stepBy is -1, so it ended up showing the correct file size on the right size of the slash. The progress bar itself always showed 100% only jumping back to 99% on EOF. Additionally, it was not detected as indefinite when building my own as this only checks for -1, not 0. So this was never executed. But using the string constructor correctly set it to -1 thus triggering the indefinite code. |
Thanks @mordechaim ! These will be fixed in the next release. |
I think I know your whole codebase by now 😉, it took me some half-hour or so. |
A pull request would be welcome! |
Do you want to handle 0 max as indefinite? Also, should changing the max affect the indefinite state even after start? |
Or perhaps use -1 as the default value of the initial max in the builder. |
-1 should be the default max of the initial max. 0 means an empty sequence. |
I use
ProgressBar.wrap(InputStream, ProgressBarBuilder)
where the stream is created byURL.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).The text was updated successfully, but these errors were encountered: