All pastes #526663 Raw Edit

Something

public text v1 · immutable
#526663 ·published 2007-05-31 22:03 UTC
rendered paste body
  public String fetchURLStream(String targetUrl) throws MalformedURLException, ConnectException, IOException {
    URL url = new URL(targetUrl);
    InputStream in = url.openStream();
    return processStream(in);
  }

  protected String processStream(InputStream is) throws IOException {
    return processStream(new InputStreamReader(is));
  }

  protected String processStream(Reader r) throws IOException {
    BufferedReader br = new BufferedReader(r);
    StringBuffer sb = new StringBuffer();
    String tmp = br.readLine();
    while (tmp != null) {
      sb.append(tmp);
      sb.append("\n");
      tmp = br.readLine();
    }
    r.close();
    return sb.toString();
  }