Пример #1
0
  public String readResponse(HttpResponse response) {
    String output = "";

    HttpEntity entity = response.getEntity();

    try {
      trapException(response.getStatusLine().getStatusCode());
    } catch (CrowdFlowerException e1) {
      e1.printStackTrace();
    }

    InputStream instream;
    try {
      instream = entity.getContent();
      BufferedReader reader = new BufferedReader(new InputStreamReader(instream));

      // do something useful with the response
      output = output + reader.readLine();
      instream.close();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return output;
  }
Пример #2
0
  public String urlReader(URL crowdFlower) {
    String jsonInput = "";

    try {
      URLConnection yc = crowdFlower.openConnection();
      BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
      String inputLine;

      while ((inputLine = in.readLine()) != null) {
        jsonInput = jsonInput + inputLine;
      }

      in.close();

      trapException(jsonInput);

    } catch (IOException e) {
      e.printStackTrace();
    } catch (CrowdFlowerException e) {
      e.printStackTrace();
    }

    return jsonInput;
  }