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

  • SEARCH
  • Home
  • 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 8089341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:21:57+00:00 2026-06-05T19:21:57+00:00

I get BufferedReader from the following networking code. URL url = new URL(request); HttpURLConnection

  • 0

I get BufferedReader from the following networking code.

    URL url = new URL(request);
    HttpURLConnection httpUrlConnection = (HttpURLConnection)url.openConnection();
    InputStream inputStream = httpUrlConnection.getInputStream();
    bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
  1. I was wondering, which way give higher efficiency in term of execution speed?
  2. Is 1024 size a good choice for Android? Or, is there any system constant value I can use?

        int charRead = 0;
        char[] buffer = new char[1024];
        StringBuffer stringBuffer = new StringBuffer();
        while ((charRead = bufferedReader.read(buffer)) > 0) {
            stringBuffer.append(buffer, 0, charRead);
        }
    

        String line = "";
        StringBuffer stringBuffer = new StringBuffer();
        while ((line = bufferedReader.readLine()) != null) {
            stringBuffer.append(line);
        }
  • 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-05T19:21:58+00:00Added an answer on June 5, 2026 at 7:21 pm

    I think the first approach is more efficient, but I’d rather set higher buffer size ex. 8*1024. This is default CoreConnectionPNames.SOCKET_BUFFER_SIZE in HttpClient.
    I’d rather say that something below 8*1024 is unreasonable because most of HTTP buffers are set to 8*1024.

    In the second approach you’re assuming new line characters in the stream. What in case of 20MB json optimized in such way that there is no new line characters? This will blow your app.

    A line is considered to be terminated by any one of a line feed (‘\n’), a carriage return (‘\r’), or a carriage return followed immediately by a linefeed.

    In my opinion the best choice is to use multiplication of 8*1024. The upper constraint is bound to size of memory and connection speed with respect to stream’s buffer processing time.

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

Sidebar

Related Questions

I have the following code to perform a GET request on the following URL:
I am trying to get an InputStream from a URL. The URL can be
I am using following code to get data from the Server and if the
I used url.openConnection() to get text from a webpage but i got time delay
I am using BufferedReader to get data fro ma url. URL url = new
Consider this following code (that retrieves the response from a HTTP request and prints
I am trying to retrieve the values from the following url: http://rentopoly.com/ajax.php?query=Bo . I
I am new at java. I am doing the following: Read from file, then
I am using the following code to get a page's source which is a
I have a problem in getting Hebrew characters from a http get request. I'm

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.