package camelinaction.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class IOHelper {
/**
* Loads the entire stream into memory as a String and returns it.
* <p/>
* <b>Notice:</b> This implementation appends a <tt>\n</tt> as line
* terminator at the of the text.
*/
public static String loadText(InputStream in) throws IOException {
StringBuilder builder = new StringBuilder();
try (InputStreamReader isr = new InputStreamReader(in)) {
BufferedReader reader = new BufferedReader(isr);
while (true) {
String line = reader.readLine();
if (line != null) {
builder.append(line);
builder.append("\n");
} else {
break;
}
}
}
return builder.toString();
}
}