out of memory error while converting inputstream to string

I am getting the out of memory exception when I am trying to convert InputStream to String. Here my json response is too large near about 4mb and it contains some special characters also some thing like this:

·&nbsp; &nbsp; &nbsp; &nbsp;  Scope of Work : Integrate RBS6601, DUL, Data test, Create COP\r<br />\r<br /> \r<br />\r<br />·&nbsp; &nbsp;

This issue is not reproducible in all Android devices in low end phones I am getting this issue. How can I overcome this issue, can anybody help me on this..

I am using the below logic to convert it:

InputStream is = httpResponse.getEntity().getContent();
String output = null;
BufferedReader br = new BufferedReader(new InputStreamReader(is));
//store  response in buffer
while ((output = br.readLine()) != null) {
    stringBuffer.append(output);
}
stringBuffer.trimToSize();

getting the below error:

java.lang.OutOfMemoryError
at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:124)
at java.lang.StringBuilder.append(StringBuilder.java:271)
at java.io.BufferedReader.readLine(BufferedReader.java:417)
at com.ldoapps.activitymanager.services.DownloadData.postData(DownloadData.java:359)
at com.ldoapps.activitymanager.services.DownloadData.doInBackground(DownloadData.java:239)
at com.ldoapps.activitymanager.services.DownloadData.onHandleIntent(DownloadData.java:220)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)


Download out.of.memory.error.while.converting.inputstream.to.string.zip
Direct Link


Download


Download out.of.memory.error.while.converting.inputstream.to.string.zip
Mediafire


Download


Download out.of.memory.error.while.converting.inputstream.to.string.zip
Zippyshare


Download

Both comments and pings are currently closed.

Comments are closed.