Android URL Download downloadJson(URI uri)

Here you can find the source of downloadJson(URI uri)

Description

download Json

Declaration

private static String downloadJson(URI uri) 

Method Source Code

//package com.java2s;

import java.io.BufferedReader;
import java.io.IOException;

import java.io.InputStreamReader;

import java.net.URI;

import java.util.zip.GZIPInputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

public class Main {
    private static final String TAG = "SOHelper";

    private static String downloadJson(URI uri) {
        try {//from w w  w  . j  a  va  2s  . co m
            Log.i(TAG, "downloading user flair from " + uri);
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(uri);
            HttpResponse httpResponse = httpClient.execute(httpGet);
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(new GZIPInputStream(httpResponse
                            .getEntity().getContent())), 8 * 1024);

            StringBuffer response = new StringBuffer();
            String line;
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();
            return response.toString();

        } catch (IOException ex) {
            Log.e(TAG, String.format("error downloading flair (%s)", uri));
            return null;
        }
    }
}

Related

  1. downloadFile(String downloadUrl, String outputFilePath)
  2. downloadFile(URL url, OutputStream output)
  3. downloadHtmlPage(String pageUrl)
  4. downloadUrl(String urlString)
  5. getJSONResponseFromURL(String url, Hashtable httpGetParams)
  6. getURLString(String urlStr)
  7. getBytesFromUrl(String url)
  8. getWebContent(String pvUrl)
  9. sendPOST(final String myurl, final String paramns)