From 9ba1410a46cb938e1a5dd53f5e6f769c455fadd8 Mon Sep 17 00:00:00 2001 From: samskivert Date: Sun, 12 Jul 2009 20:55:37 +0000 Subject: [PATCH] Allow code that already has a reader to rock right on as well. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2587 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/io/StreamUtil.java | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/java/com/samskivert/io/StreamUtil.java b/src/java/com/samskivert/io/StreamUtil.java index 4db8f2c6..d5034481 100644 --- a/src/java/com/samskivert/io/StreamUtil.java +++ b/src/java/com/samskivert/io/StreamUtil.java @@ -91,21 +91,6 @@ public class StreamUtil } } - /** - * Reads the contents of the supplied stream into a string using the supplied {@link Charset}. - */ - public static String toString (InputStream stream, String charset) - throws IOException - { - InputStreamReader reader = new InputStreamReader(stream, charset); - char[] inbuf = new char[4096]; - StringBuffer outbuf = new StringBuffer(); - for (int read = 0; (read = reader.read(inbuf)) > 0; ) { - outbuf.append(inbuf, 0, read); - } - return outbuf.toString(); - } - /** * Copies the contents of the supplied input stream to the supplied output stream. */ @@ -117,4 +102,27 @@ public class StreamUtil out.write(buffer, 0, read); } } + + /** + * Reads the contents of the supplied stream into a string using the supplied {@link Charset}. + */ + public static String toString (InputStream stream, String charset) + throws IOException + { + return toString(new InputStreamReader(stream, charset)); + } + + /** + * Reads the contents of the supplied reader into a string. + */ + public static String toString (Reader reader) + throws IOException + { + char[] inbuf = new char[4096]; + StringBuffer outbuf = new StringBuffer(); + for (int read = 0; (read = reader.read(inbuf)) > 0; ) { + outbuf.append(inbuf, 0, read); + } + return outbuf.toString(); + } }