Here you can find the source of getStringFromConnection(HttpURLConnection connection)
public static String getStringFromConnection(HttpURLConnection connection)
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; public class Main { public static String getStringFromConnection(HttpURLConnection connection) { InputStream inputStream = null; DataInputStream dataInputStream = null; String lineData, completeData = ""; try {// w ww.j a va 2s .co m boolean error = false; if (connection.getResponseCode() >= 400) { inputStream = connection.getErrorStream(); error = true; } else { inputStream = connection.getInputStream(); } dataInputStream = new DataInputStream(new BufferedInputStream(inputStream)); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(dataInputStream)); while ((lineData = bufferedReader.readLine()) != null) { if (lineData.startsWith("ERROR")) { inputStream.close(); dataInputStream.close(); bufferedReader.close(); return lineData; } completeData += lineData; } if (error) System.out.println("Error Connecting to AutoUpdater. Response Follows: \n" + completeData); inputStream.close(); bufferedReader.close(); dataInputStream.close(); } catch (IOException e) { e.printStackTrace(); } return completeData; } }