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 6132593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:07:15+00:00 2026-05-23T17:07:15+00:00

I’m pretty new to coding with streams but now I have to do it

  • 0

I’m pretty new to coding with streams but now I have to do it for more efficient Http coding.

Here is code that I wrote(not working) to get ContentProducer for HttpClient:

public static ContentProducer getContentProducer(final Context context, final UUID gId)
    {
        return new ContentProducer()
        {
            public void writeTo(OutputStream outputStream) throws IOException
            {
                outputStream = new Base64.OutputStream(new FileOutputStream(StorageManager.getFileFromName(context, gId.toString())));

                outputStream.flush();
            }
        };
    }

I’m using Base64 streaming encoder from here: http://iharder.sourceforge.net/current/java/base64/
My goal is to use this function to provide data that I read from binary file to HttpClient as base64 encoded stream.

This is how I consume content producers:

private MyHttpResponse processPOST(String url, ContentProducer requestData)
    {
        MyHttpResponse response = new MyHttpResponse();

        try
        {
            HttpPost request = new HttpPost(serviceURL + url);
            HttpEntity entity = new EntityTemplate(requestData);
            request.setEntity(entity);

            ResponseHandler<String> handler = new BasicResponseHandler();
            response.Body = mHttpClient.execute(request, handler);
        }
        catch (HttpResponseException e)
        {

        }
        catch (Throwable e)
        {

        }

        return response;
    }

I have another ContentProducer which works with GSON streamer(and it’s working):

public ContentProducer getContentProducer(final Context context)
    {
        return new ContentProducer()
        {
            public void writeTo(OutputStream outputStream) throws IOException
            {
                Gson myGson = MyGsonWrapper.getMyGson();
                JsonWriter writer = new JsonWriter(new OutputStreamWriter(outputStream, "UTF-8"));

                writer.beginObject();

                // stuff

                writer.endObject();

                writer.flush();
            }
        };
    }

My question is: How to make my first example work. Am I doing it correctly? Right now I get empty post on server side, so it seems like no data coming through.

  • 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-23T17:07:16+00:00Added an answer on May 23, 2026 at 5:07 pm

    EDIT:

    I believe that the issue is that you are being passed an OutputStream in your ContentProviders writeTo() method, and you are overwriting it with your own OutputStream. The contract of that class/method probably requires you to write your data to the OutputStream passed to you.

    Based on looking at the Android Documentation, I do not see a way for you to specify the OutputStream to use, so you will probably need to just write out the data of the file to the OutputStream that is passed in.

    Instead, you should do something like this:

    public void writeTo(OutputStream outputStream) throws IOException
    {
        byte[] buf = createByteBufferFromFile(StorageManager.getFileFromName(context, gId.toString()));
        outputStream.write(buf);
        outputStream.flush();
    }
    

    Of course you will need to provide an implementation to the createByteBufferFromFile(…) method that I mention. Again, you should note that it is not likely that you will be using the Base64 OutputStream, so if that is a necessity, then you may have to find a different approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.