Reading/writing from streams is remarkably painful in Java.
public static String getStreamContents(InputStream stream) throws IOException {
StringBuilder content = new StringBuilder()
Reader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"))
String lineSeparator = System.getProperty("line.separator");
try {
String line
while ((line = reader.readLine()) != null) {
content.append(line + lineSeparator)
}
return content.toString()
} finally {
reader.close()
}
}