- // do NOT close the reader, or the related stream will be closed, too
- // reader.close();
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(stream));
-
- StringBuilder builder = new StringBuilder();
- for (String line = reader.readLine(); line != null; line = reader
- .readLine()) {
- builder.append(line);
- builder.append("\n");
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ write(stream, out);
+ return out.toString("UTF-8");
+ } finally {
+ // do NOT close, or the related stream will be closed, too
+ // out.close();