Ramp up the fancy.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@2589 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2009-07-12 21:18:45 +00:00
parent 53effafe58
commit 0711e29d39
+5 -3
View File
@@ -20,12 +20,13 @@
package com.samskivert.io; package com.samskivert.io;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Writer;
import java.io.Reader; import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import static com.samskivert.Log.log; import static com.samskivert.Log.log;
@@ -94,13 +95,14 @@ public class StreamUtil
/** /**
* Copies the contents of the supplied input stream to the supplied output stream. * Copies the contents of the supplied input stream to the supplied output stream.
*/ */
public static void copy (InputStream in, OutputStream out) public static <T extends OutputStream> T copy (InputStream in, T out)
throws IOException throws IOException
{ {
byte[] buffer = new byte[4096]; byte[] buffer = new byte[4096];
for (int read = 0; (read = in.read(buffer)) > 0; ) { for (int read = 0; (read = in.read(buffer)) > 0; ) {
out.write(buffer, 0, read); out.write(buffer, 0, read);
} }
return out;
} }
/** /**
@@ -109,7 +111,7 @@ public class StreamUtil
public static String toString (InputStream stream, String charset) public static String toString (InputStream stream, String charset)
throws IOException throws IOException
{ {
return toString(new InputStreamReader(stream, charset)); return copy(stream, new ByteArrayOutputStream()).toString(charset);
} }
/** /**