Reputation: 203
I am following the examples from an android course at udacity made by google and I replaced the url of the example with an other one but I can only see, using the LOG only a small portion of the url I am downloading.
public class FetchWeatherTask extends AsyncTask<Void, Void, Void> {
private final String LOG_TAG = FetchWeatherTask.class.getSimpleName();
@Override
protected Void doInBackground(Void... params) {
// These two need to be declared outside the try/catch
// so that they can be closed in the finally block.
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
// Will contain the raw JSON response as a string.
String forecastJsonStr = null;
try {
// Construct the URL for the OpenWeatherMap query
// Possible parameters are available at OWM's forecast API page, at
// http://openweathermap.org/API#forecast
URL url = new URL("http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7");
// Create the request to OpenWeatherMap, and open the connection
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();
// Read the input stream into a String
InputStream inputStream = urlConnection.getInputStream();
StringBuffer buffer = new StringBuffer();
if (inputStream == null) {
// Nothing to do.
return null;
}
reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
// Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
// But it does make debugging a *lot* easier if you print out the completed
// buffer for debugging.
buffer.append(line + "\n");
}
if (buffer.length() == 0) {
// Stream was empty. No point in parsing.
return null;
}
forecastJsonStr = buffer.toString();
Log.v(LOG_TAG, "Forecast JSON String: " + forecastJsonStr);
} catch (IOException e) {
Log.e(LOG_TAG, "Error ", e);
// If the code didn't successfully get the weather data, there's no point in attemping
// to parse it.
return null;
} finally{
if (urlConnection != null) {
urlConnection.disconnect();
}
if (reader != null) {
try {
reader.close();
} catch (final IOException e) {
Log.e(LOG_TAG, "Error closing stream", e);
}
}
}
return null;
}
}
Is there a limitation of how much data you can download?
My response in the log:
V/FetchWeatherTask﹕ Forecast JSON String: {"cod":"200","message":0.0506,"city":{"id":0,"name":"Mountain View","country":"US","coord":{"lat":37.4056,"lon":-122.0775}},"cnt":7,"list":[{"dt":1427572800,"temp":{"day":22.34,"min":6.06,"max":22.41,"night":6.06,"eve":16.73,"morn":9.62},"pressure":995.73,"humidity":49,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":1.95,"deg":339,"clouds":32},{"dt":1427659200,"temp":{"day":23.84,"min":5.16,"max":23.84,"night":6.98,"eve":16.84,"morn":5.16},"pressure":993.22,"humidity":46,"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"speed":1.33,"deg":297,"clouds":0},{"dt":1427745600,"temp":{"day":16.45,"min":8.95,"max":17.99,"night":11.51,"eve":17.99,"morn":8.95},"pressure":1011.5,"humidity":0,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":2.24,"deg":292,"clouds":51},{"dt":1427832000,"temp":{"day":14.62,"min":8.79,"max":18.33,"night":12.9,"eve":18.33,"morn":8.79},"pressure":1014.65,"humidity":0,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"speed":4.02,"deg":324,"clouds":0},{"dt":1427918400,"temp":{"day":15.37,"min":9.92,"max":17.5,"night":14.15,"eve":17.5,"morn":9.92},"pressure":1012.74,"humidity":0,"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"speed":3.46,"deg":312,"clouds":5},{"dt":1428004800,"temp":{"day":14.2,"min":10.92,"max":16.56,"night":14.1,"eve":16.56,"morn":10.92},"pressure":1011.2,"humidity":0,"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"speed":6.67,"deg":330,"clouds":0},{"dt":1428091200,"temp":{"day":16.39,"min":10.38,"max":17.89,"night":11.01,"eve":17.89,"morn":10.38},"pressure":1014.68,"humidity":0,"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"speed":3.81,"deg":338,"clouds":0}]}
Upvotes: 0
Views: 273
Reputation: 3688
Definitely there is a limit, for larger logs such as json responses, always try to segment the response (json response is collection of objects like array of items, try to convert response into jason array and get one by one) and print several log functions rather than trying to print the whole response in a single log function.
Upvotes: 1