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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:22:16+00:00 2026-06-15T11:22:16+00:00

The following code : // // Define HTTP Post and content // HttpPost httppost

  • 0

The following code :

//
// Define HTTP Post and content
//
HttpPost httppost = new HttpPost(url);
ByteArrayEntity be = new ByteArrayEntity(strPostData.getBytes("UTF-8"));
httppost.setEntity(be);
//
// Define HTTP Client
// 
HttpClient httpclient = new DefaultHttpClient();
HttpParams httpParameters = httpclient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 10 * 1000);
//      
// Sets the default socket timeout
// in milliseconds which is the timeout for waiting for data.
//
int timeoutSocket = 10000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpResponse response = httpclient.execute(httppost);
//      
// This line takes too long on big responses
//
String content = EntityUtils.toString(response.getEntity());

The last line (EntityUtils.toString) takes too long when my response contains a large amount of Bytes.

I’m using HTTP Post to retrieve PDF files (up to 500 Kb) and it may take 1 or 2 seconds on each request, which is too much.

EDIT For Information : The PDF file is base 64 encoded and wrapped into XML Tag (the string is parsed after reception).

Is there any way to get my String response a faster way ?

EDIT 2 : in order to know how much time took my EntityUtils.toString, I made a method :

public static void logger(String header, String content) {
    Date dateActualLog = new Date();
    long milliseconds = (dateActualLog.getTime() - dateLastLog.getTime());
    Log.d(header, String.valueOf(milliseconds) + " => " + content);
    dateLastLog = dateActualLog;
}

(fyi : dateLastLog is a static variable)

I modified the above code like this :

//      
// This line takes too long on big responses
//
logger(TAG, "toString ...");
String content = EntityUtils.toString(response.getEntity());
logger(TAG, "toString OK");

Thanks in advance.

  • 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-06-15T11:22:17+00:00Added an answer on June 15, 2026 at 11:22 am

    Well, the first simple thing to try would be to ensure that your web-server is supplying a correct ContentLength header in the HTTP response. Looking at some version of the source-code for HttpCore’s EntityUtils class, we see that if this information is not available, it defaults to using a CharArrayBuffer of just 4k, buffering 1k of data when writing. On the 4th, 5th, and subsequent writes to the CharArrayBuffer (all the way up to 500, you say), it gradually increments the buffer by 1k … using System.arrayCopy(). Yuck. There’s your performance misery right there.

    If speed is really important to you however, you’ll avoid using EntityUtils entirely. It’s just not responsible to turn a stream into a temporary 500k String … especially on a phone! You’ll need to find or write a Base64DecodingInputStream or Base64DecodingReader to wrap your InputStream from response.getEntity().getContent(), and feed that … instead of a String … to your parser.

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

Sidebar

Related Questions

Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
The following code works fine #define open { #define close } #include<stdio.h> #define int
I have the following code snippet: #ifdef DO_LOG #define log(p) record(p) #else #define log(p)
Can I define upload and browse baseurl to ckfinder dynamicly in the following code?
I have the following code: #include <iostream> #define BOOST_TEST_MODULE my test #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_CASE(
Why does the following code give me a segmentation fault? #define MAXROWS 10 #define
consider the following code scenario: <?php //widgetfactory.class.php // define a class class WidgetFactory {
I have the following code: #include <stdio.h> #include <pthread.h> #define THREAD_CNT 10 #define ITER
I have the following code: #include <stdlib.h> #include <stdio.h> #include <pthread.h> #define NUM_THREADS 100
I am trying to understand the following code: #include<stdio.h> #include<stdlib.h> #include<sys/io.h> #define baseport 0x378

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.