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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:28:08+00:00 2026-05-21T17:28:08+00:00

I receive gziped JSON from web service and then i unzip it (size of

  • 0

I receive gziped JSON from web service and then i unzip it (size of unziped JSON is 3.2MB).
I need to transform received InputStream to String so i can then create JSONObject and parse it. I do it with this code:

public static String InputStreamToString(InputStream in) 
    throws IOException {

    BufferedInputStream bis = new BufferedInputStream(in);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    int result = bis.read();

    while(result != -1) {
      byte b = (byte)result;
      buf.write(b);
      result = bis.read();
    }        
    return buf.toString();
}

I receive java.lang.OutOfMemoryError on the last line: “return buf.toString();” on the emulator and device with 288MB Ram.

What shall i 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-21T17:28:09+00:00Added an answer on May 21, 2026 at 5:28 pm

    Reading in a byte at a time is so 1990’s. Either use HttpClient and BasicResponseHandler, or at least read the data in respectable chunks and append them using a StringBuilder.

    Assuming you are still having the problem, the issue is that there is no single block of memory that is big enough for your string, based upon other things your app has been doing. The Android garbage collector is not a compacting collector, so it is possible to have lots of free heap space yet not enough for a specific allocation request.

    In that case, you may need to switch to some sort of streaming JSON parser. If you happen to be targeting only Honeycomb and higher, you can use JSONReader. Otherwise, Jackson reportedly works on Android and apparently has a streaming mode.

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

Sidebar

Related Questions

I receive the datetime string below from a web service and try to transform
I receive a date in the format below from a json file. Im not
I receive a string from a database query, then I remove all HTML tags,
I receive Date and time from CSV file The received Date format is YYYYMMDD
I receive JSON objects from a websocket with update/create/delete flags. Based on this information,
I receive json from a webservice into a NSMutableData. That gets converted into a
I receive response in the form of xml from a service,which i parse using
I receive a post request from client. This request contains some json data which
I receive a WCF service to communicate, so, i need to create a client
I receive from the server a JSON like the following: {0:{0:image1.jpg,1:texthere,2:0},1:{0:image66.jpg,1:texthere,2:1},2:{0:image12.jpg,1:texthere,2:2},3:{0:image44.jpg,1:texthere,2:3},4:{0:image34.jpg,1:texthere,2:4},5:{0:image33.jpg,1:texthere,2:5},6:{0:image21.jpg,1:texthere,2:6},7:{0:image32.jpg,1:texthere,2:7},8:{0:image13.jpg,1:texthere,2:8},9:{0:image11.jpg,1:texthere,2:9},10:{0:image03.jpg,1:texthere,2:10},length:12} The developer who

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.