Skip to content

Wrapped InputStream doesn't automatically detect size #127

Closed
@Markus74a

Description

I'm trying to use ProgressBar.warp() to show progress on a FileInputStream, but it will not detect the size of the stream unless I first set some initial size.

This is the current ProgressBar 0.9.3 implementation:

    public static InputStream wrap(InputStream is, ProgressBarBuilder pbb) {
        long size = Util.getInputStreamSize(is);
        if (size != -1 && pbb.initialMaxIsSet())
            pbb.setInitialMax(size);
        return new ProgressBarWrappedInputStream(is, pbb.build());
    }

Even if the InputStream size gets detected correctly, it will not use that information.

  • Behaviour (should):
  1. Use value set by user
  2. (else) Use auto-detected value
  3. (else) Use default value
  • Behaviour (is)
  1. Ignore value set by user and use auto-detected value
  2. (else) Use default value

The comparison should be !pbb.initialMaxIsSet() instead of pbb.initialMaxIsSet().

This code will not detect the correct file size:

ProgressBar.wrap(is, new ProgressBarBuilder());

This code will detect the correct file size:

ProgressBar.wrap(is, new ProgressBarBuilder().setInitialMax(123456));

Having to set a value which gets ignored is not intuitive.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions