Error de memoria al colocar JSON grande (InputStream) en la cadena
Recibo JSON gziped del servicio web y luego lo descomprimo (el tamaño de JSON descomprimido es de 3.2 MB). Necesito transformar InputStream recibido en String para poder crear JSONObject y analizarlo. Lo hago con este código:
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();
}
Recibo java.lang.OutOfMemoryError en la última línea: "return buf.toString ();" en el emulador y dispositivo con 288 MB de RAM.
¿Qué debo hacer