I\'m working on a project which connect to a web server and receive binary data. My problem is when I\'m downloading data from web server. If i send request to login or to activ
On Android you only have a limited heap size, which gets exhausted while you try to decode your entity. I think you need to use http chunking to send your data to the client (or something goes wrong and the EntityUtils think they need a much bigger array. The problem is a byte array which is to big not to small. Have a look at this posts:
Ok, try this..
HttpResponse response = httpclient.execute(httppost);
// get response entity
HttpEntity entity = response.getEntity();
// convert entity response to string
if (entity != null)
{
InputStream is = entity.getContent();
// convert stream to string
result = convertStreamToString(is);
result = result.replace("\n", "");
}
And for conversion of InputStream to String
public String convertStreamToString(InputStream inputStream)
{
BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
return total.toString();
}
or
use Apache Commons library (org.apache.commons.io.IOUtils).
String total = IOUtils.toString(inputStream);
or just write to temp file,
HttpEntity.writeTo(OutputStream);
Ok as per user Philipp Reichart suggested, from package of org.apache.http.util
;
EntityUtils.toString();
is the method which allow the encoding format with String Conversion
.
and let me know still you get OutOfMemory Error
.
Thanks.