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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:12:16+00:00 2026-05-20T11:12:16+00:00

The following code is working fine in Android 1.5-2.2.1 but it’s not in 2.3

  • 0

The following code is working fine in Android 1.5-2.2.1 but it’s not in 2.3 and higher.

BufferedReader rd;
rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));

StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null){
    sb.append(line);
}
rd.close();

The stracktrace:

01-30 08:21:42.668: WARN/System.err(594): java.io.IOException: BufferedInputStream is closed
01-30 08:21:42.668: WARN/System.err(594):     at java.io.BufferedInputStream.streamClosed(BufferedInputStream.java:116)
01-30 08:21:42.728: WARN/System.err(594):     at java.io.BufferedInputStream.read(BufferedInputStream.java:274)
01-30 08:21:42.728: WARN/System.err(594):     at org.apache.harmony.luni.internal.net.www.protocol.http.UnknownLengthHttpInputStream.read(UnknownLengthHttpInputStream.java:40)
01-30 08:21:42.758: WARN/System.err(594):     at java.io.InputStreamReader.read(InputStreamReader.java:255)
01-30 08:21:42.758: WARN/System.err(594):     at java.io.BufferedReader.fillBuf(BufferedReader.java:128)
01-30 08:21:42.758: WARN/System.err(594):     at java.io.BufferedReader.readLine(BufferedReader.java:357)

Is this an issue? Has anything changed in 2.3??

  • 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-20T11:12:17+00:00Added an answer on May 20, 2026 at 11:12 am

    I noticed this as well. One thing you can do is check the state of the BufferedReader at the end of your loop:

    while((line = rd.readLine()) != null){
        sb.append(line);
        if (!rd.ready()) {
           break;
        }
    }
    rd.close();
    

    However, ready() does not guarantee that your stream is at the end. It only checks if the stream is blocked or closed.
    See BufferedReader.ready() on developer.android.com

    I think this is a bug introduced in Android OS 2.3 and above. Please contribute to the bug base on the the official android site to encourage Google to fix this problem. Unfortunately, there are already many devices that have already shipped with OS versions 2.3 to 2.3.3.

    Your situation is that you’ve probably hit the end of the file in one read and the stream is automatically closed. I think that is a bug introduced in Android 2.3 and above.

    glassonion’s post will work, but that workaround will perform very slowly on long streams of data.

    Since mobile applications may lose internet connectivity at any time, the InputStream you’re reading from may just simply be blocked and waiting for more data.

    A more proper approach may be to open a socket on a new thread, read the data and wait with a timeout to hedge against any slowness in your connection.

    The following article explains handling stalled connections quite well. Reading the summary should be enough to convince you.

    All good network applications will include timeout detection and handling. Whether you’re writing a client, and need to detect a wayward server, or writing a server and need to prevent stalled connections, timeout handling is a critical part of error handling.

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

Sidebar

Related Questions

The following code is working fine in other browsers, but is not on IE8
I'using the following code to create thumbnails using ffmpeg but it was working fine
I have the following code working fine but the problem is that it always
I have the following code working fine, but I'm unable to add a zoom
The following code writes the data and is working fine, but I want to
I have the following code that is working fine in jsfiddle - http://jsfiddle.net/darkajax/FHZBy/ I've
I have following code And it is working fine in AIR device simulator on
Is the following stored procedure code robust for multi-user application. It is working fine.
Why is the following code not working? if(EventLog.Exists(Foo)) { EventLog.Delete(Foo); } if(EventLog.Exists(Foo) == false)
can anybody tell me why is the following code not working? <script type=text/javascript src=../../Scripts/jquery.js></script>

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.