I am working on http get request on android.
I receive a huge amount of json data from server, a string is unable to handle or store that data and getting OutOfMemory Exception.
Then I tried to save it in arrayList which can store a maximum of Integer.Maximum value. but it is getting OutOfMemory exception while storing at ~8970 location.
Here is my link which has json data.
http://ec2-50-19-105-251.compute-1.amazonaws.com/ad/Upload/getitemlist10122013035042.txt
here is my code:
ArrayList<String> newarr = new ArrayList<String>();
try {
URL url = new URL(urlFilePath);
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.setRequestMethod("GET");
// urlConnection.setDoOutput(true);
// connect
urlConnection.connect();
// Stream used for reading the data from the internet
InputStream inputStream = urlConnection.getInputStream();
// create a buffer...
byte[] buffer = new byte[1024];
int bufferLength = 0;
int check;
while ((bufferLength = inputStream.read(buffer)) > 0) {
String decoded = new String(buffer, 0, bufferLength);
newarr.add(decoded); // OutOfMemory Exception.
}
fileOutput.close();
buffer = null;
inputStream.close();
String path = file.getAbsolutePath();
return path;
} catch (final MalformedURLException e) {
e.printStackTrace();
return "";
} catch (final IOException e) {
e.printStackTrace();
return "";
} catch (final Exception e) {
System.out.println("EXCEPTION:: " + e.getMessage());
e.printStackTrace();
return "";
}