Coder Social home page Coder Social logo

Comments (15)

mordechaim avatar mordechaim commented on August 16, 2024 1

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.

from progressbar.

mordechaim avatar mordechaim commented on August 16, 2024 1

So it is still a bug, right?

Yes, this is a bug. Here you do it correctly.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

Just to confirm -- you mean that you want to override the default size (as computed by the underlying stream) to a customized size using ProgressBarBuilder?

Why do you want to do this? I assume that the underlying actual file size is the size of the progress bar you want?

from progressbar.

mordechaim avatar mordechaim commented on August 16, 2024

you want to override the default size (as computed by the underlying stream)

Wrapping the stream without setting the max initial ended up showing question marks (unknown file size) and a messed up progress bar:
image

So I set the max initial to the file size (correctly shown at the right side of the /) but the total bytes downloaded (at the left of /) is off by one even though the actual file is downloaded in full and my OS shows the file size correctly.

from progressbar.

mordechaim avatar mordechaim commented on August 16, 2024

Just checked, when using the ProgressBar.wrap(InputStream, String) constructor, it will show question marks, but using ProgressBar.wrap(InputStream, ProgressBarBuilder) even if I don't set the max initial it will show exactly like the first snip, i.e. correct file size but still off by one in progress.

from progressbar.

mordechaim avatar mordechaim commented on August 16, 2024

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.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

So it is still a bug, right?
In https://github.com/ctongfei/progressbar/blob/master/src/main/java/me/tongfei/progressbar/wrapped/ProgressBarWrappedInputStream.java#L45, if stream.read() == -1, the progress bar should not stepBy -1.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

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.

This surprises me -- if it is not a FileInputStream the max initial should not be detected?

from progressbar.

mordechaim avatar mordechaim commented on August 16, 2024

This surprises me -- if it is not a FileInputStream the max initial should not be detected?

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.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

Thanks @mordechaim ! These will be fixed in the next release.

from progressbar.

mordechaim avatar mordechaim commented on August 16, 2024

I think I know your whole codebase by now 😉, it took me some half-hour or so.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

A pull request would be welcome!

from progressbar.

mordechaim avatar mordechaim commented on August 16, 2024

Do you want to handle 0 max as indefinite? Also, should changing the max affect the indefinite state even after start?

from progressbar.

mordechaim avatar mordechaim commented on August 16, 2024

Do you want to handle 0 max as indefinite?

Or perhaps use -1 as the default value of the initial max in the builder.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

-1 should be the default max of the initial max. 0 means an empty sequence.

from progressbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.