ctongfei / progressbar

Terminal-based progress bar for Java / JVM
http://tongfei.me/progressbar/
MIT License
1.07k stars 102 forks source link

Wrap outputstream as well #114

Closed azachar closed 2 years ago

azachar commented 2 years ago

Hi there! A very nice tool!

Could you please add also support for output streams?

For instance the library I am using for datalake is providing only output stream, so what I did is this:

ProgressBar pb = new ProgressBarBuilder()
                .setTaskName("Downloading "+pathItem.getName())
                .setUnit("MiB", 1024*1024)
                .build();

        pb.maxHint(pathItem.getContentLength());

OutputStream targetStream = new FileOutputStream(outputFile) {
            @Override
            public void write(byte[] b) throws IOException {
                super.write(b);
                pb.stepBy(b.length);
            }

            @Override
            public void write(int b) throws IOException {
                super.write(b);
                pb.step();
            }

            @Override
            public void write(byte[] b, int off, int len) throws IOException {
                super.write(b, off, len);
                pb.stepBy(b.length);
            }
        };

I guess that anonym class should be part of this project somehow.

Cheers, Andrej

ctongfei commented 2 years ago

Thanks Andrej for the suggestion! I guess we should do OutputStream and Writer then?

azachar commented 2 years ago

Sure, that would be cool!

Ps: also adding a method for a complete done would be great!

Cheers,

Andrej

Dňa 2021-10-07 o 1:33 užívateľ Tongfei Chen @.***> napísal:

 Thanks Andrej for the suggestion! I guess we should do OutputStream and Writer then?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

ctongfei commented 2 years ago

@azachar what do you mean by a complete done?

azachar commented 2 years ago

Yes

Dňa 2021-10-07 o 23:38 užívateľ Tongfei Chen @.***> napísal:

 @azachar what do you mean by a complete done?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

ctongfei commented 2 years ago

Isn't pb.close() what you need?

azachar commented 2 years ago

I guess so, thanks for update, i might have missed it in doc.

Dňa 2021-10-08 o 18:45 užívateľ Tongfei Chen @.***> napísal:

 Isn't pb.close() what you need?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.