Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084904
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:29:57+00:00 2026-05-20T18:29:57+00:00

I watched the HttpClient progress code but I still have questions I couldn’t find

  • 0

I watched the HttpClient progress code but I still have questions I couldn’t find answer
Where to get this ProgressListener to put the constructor parameter? And how to use the code correctly? Please help

Here is the code

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;

public class CountingMultipartEntity extends MultipartEntity {

    private final ProgressListener listener;

    public CountingMultipartEntity(final ProgressListener listener) {
        super();
        this.listener = listener;
    }

    public CountingMultipartEntity(final HttpMultipartMode mode, final ProgressListener listener) {
        super(mode);
        this.listener = listener;
    }

    public CountingMultipartEntity(HttpMultipartMode mode, final String boundary,
            final Charset charset, final ProgressListener listener) {
        super(mode, boundary, charset);
        this.listener = listener;
    }

    @Override
    public void writeTo(final OutputStream outstream) throws IOException {
        super.writeTo(new CountingOutputStream(outstream, this.listener));
    }

    public static interface ProgressListener {
        void transferred(long num);
    }

    public static class CountingOutputStream extends FilterOutputStream {

        private final ProgressListener listener;
        private long transferred;

        public CountingOutputStream(final OutputStream out,
                final ProgressListener listener) {
            super(out);
            this.listener = listener;
            this.transferred = 0;
        }


        public void write(byte[] b, int off, int len) throws IOException {
            out.write(b, off, len);
            this.transferred += len;
            this.listener.transferred(this.transferred);
        }

        public void write(int b) throws IOException {
            out.write(b);
            this.transferred++;
            this.listener.transferred(this.transferred);
        }
    }
}

Can I implement the interface like this?

...
public static interface ProgressListener {
        void transferred(long num);
    }
    public static class Progress implements ProgressListener
    {

      public void transferred(long num) {
//            // update the progress bar or whatever else you might want to do

        }

    }
...

But how can I init the ProgressListener as for this outer class which contains HttpClient then?

CountingMultiPartEntity entity = new CountingMultiPartEntity(new ProgressListener() {

        public void transferred(long num) {
            // update the progress bar or whatever else you might want to do
        }
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:29:58+00:00Added an answer on May 20, 2026 at 6:29 pm

    You’ll need to construct an implementation of the ProgressListener interface yourself if you don’t have any classes that implement it already. For things like listeners, this is commonly done with an anonymous inner class.

    CountingMultipartEntity entity = new CountingMultipartEntity(new ProgressListener() {
        @Override
        public void transferred(long num) {
            // update the progress bar or whatever else you might want to do
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I watched few videos/webcasts about Oslo but I still fail to see how it
I recently watched this youtube tutorial on the Null Object design pattern. Even though
I have read a lot of articles on Dependency Injection as well as watched
After reading the nice answers in this question , I watched the screencasts by
Having Watched this video by Greg Yound on DDD http://www.infoq.com/interviews/greg-young-ddd I was wondering how
I watched this Introduction to Moq video on Dimecasts.net. In the video, when the
I watched the http://www.subsonicproject.com/docs/Using_SimpleRepository screencast, but I am left wondering... how do you migrate
I watched this webcast recently, and I got the sense that a lot of
i have watched a site which has taught iphone application using dashcode.it says dashcode
I just watched the following video: Introduction to Node.js and still don't understand how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.