scolebourne 2004/08/13 16:51:41 Modified: io/src/test/org/apache/commons/io CopyUtilsTest.java io/src/java/org/apache/commons/io CopyUtils.java FileUtils.java Log: Deprecate CopyUtils (reverting to v1.0) Revision Changes Path 1.8 +1 -183 jakarta-commons/io/src/test/org/apache/commons/io/CopyUtilsTest.java Index: CopyUtilsTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/CopyUtilsTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- CopyUtilsTest.java 31 Jul 2004 10:40:47 -0000 1.7 +++ CopyUtilsTest.java 13 Aug 2004 23:51:41 -0000 1.8 @@ -80,7 +80,6 @@ // Tests // ---------------------------------------------------------------- - //----------------------------------------------------------------------- public void testCopy_byteArrayToOutputStream() throws Exception { ByteArrayOutputStream baout = new ByteArrayOutputStream(); OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); @@ -103,32 +102,6 @@ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); } - public void testCopy_byteArrayToWriter_nullEncoding() throws Exception { - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - Writer writer = new java.io.OutputStreamWriter(baout, "US-ASCII"); - - CopyUtils.copy(inData, writer, null); - writer.flush(); - - assertEquals("Sizes differ", inData.length, baout.size()); - assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); - } - - public void testCopy_byteArrayToWriter_Encoding() throws Exception { - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - Writer writer = new java.io.OutputStreamWriter(baout, "US-ASCII"); - - CopyUtils.copy(inData, writer, "UTF8"); - writer.flush(); - - byte[] bytes = baout.toByteArray(); - bytes = new String(bytes, "UTF8").getBytes("US-ASCII"); - assertTrue("Content differs", Arrays.equals(inData, bytes)); - } - - //----------------------------------------------------------------------- public void testCopy_inputStreamToOutputStream() throws Exception { InputStream in = new ByteArrayInputStream(inData); in = new YellOnCloseInputStream(in); @@ -159,40 +132,6 @@ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); } - public void testCopy_inputStreamToWriter_nullEncoding() throws Exception { - InputStream in = new ByteArrayInputStream(inData); - in = new YellOnCloseInputStream(in); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - Writer writer = new java.io.OutputStreamWriter(baout, "US-ASCII"); - - CopyUtils.copy(in, writer, null); - writer.flush(); - - assertTrue("Not all bytes were read", in.available() == 0); - assertEquals("Sizes differ", inData.length, baout.size()); - assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); - } - - public void testCopy_inputStreamToWriter_Encoding() throws Exception { - InputStream in = new ByteArrayInputStream(inData); - in = new YellOnCloseInputStream(in); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - Writer writer = new java.io.OutputStreamWriter(baout, "US-ASCII"); - - CopyUtils.copy(in, writer, "UTF8"); - writer.flush(); - - assertTrue("Not all bytes were read", in.available() == 0); - byte[] bytes = baout.toByteArray(); - bytes = new String(bytes, "UTF8").getBytes("US-ASCII"); - assertTrue("Content differs", Arrays.equals(inData, bytes)); - } - - //----------------------------------------------------------------------- public void testCopy_readerToOutputStream() throws Exception { InputStream in = new ByteArrayInputStream(inData); in = new YellOnCloseInputStream(in); @@ -213,39 +152,6 @@ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); } - public void testCopy_readerToOutputStream_nullEncoding() throws Exception { - InputStream in = new ByteArrayInputStream(inData); - in = new YellOnCloseInputStream(in); - Reader reader = new java.io.InputStreamReader(in, "US-ASCII"); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - - CopyUtils.copy(reader, out, null); - // note: this method *does* flush. - // note: we don't flush here; this IOUtils method does it for us - - assertEquals("Sizes differ", inData.length, baout.size()); - assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); - } - - public void testCopy_readerToOutputStream_Encoding() throws Exception { - InputStream in = new ByteArrayInputStream(inData); - in = new YellOnCloseInputStream(in); - Reader reader = new java.io.InputStreamReader(in, "US-ASCII"); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - - CopyUtils.copy(reader, out, "UTF16"); - // note: this method *does* flush. - // note: we don't flush here; this IOUtils method does it for us - - byte[] bytes = baout.toByteArray(); - bytes = new String(bytes, "UTF16").getBytes("US-ASCII"); - assertTrue("Content differs", Arrays.equals(inData, bytes)); - } - public void testCopy_readerToWriter() throws Exception { InputStream in = new ByteArrayInputStream(inData); in = new YellOnCloseInputStream(in); @@ -265,7 +171,6 @@ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); } - //----------------------------------------------------------------------- public void testCopy_stringToOutputStream() throws Exception { String str = new String(inData, "US-ASCII"); @@ -284,35 +189,6 @@ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); } - public void testCopy_stringToOutputStream_nullEncoding() throws Exception { - String str = new String(inData, "US-ASCII"); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - - CopyUtils.copy(str, out, null); - // note: this method *does* flush. - // note: we don't flush here; this IOUtils method does it for us - - assertEquals("Sizes differ", inData.length, baout.size()); - assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); - } - - public void testCopy_stringToOutputStream_Encoding() throws Exception { - String str = new String(inData, "US-ASCII"); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - - CopyUtils.copy(str, out, "UTF16"); - // note: this method *does* flush. - // note: we don't flush here; this IOUtils method does it for us - - byte[] bytes = baout.toByteArray(); - bytes = new String(bytes, "UTF16").getBytes("US-ASCII"); - assertTrue("Content differs", Arrays.equals(inData, bytes)); - } - public void testCopy_stringToWriter() throws Exception { String str = new String(inData, "US-ASCII"); @@ -327,62 +203,4 @@ assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); } - //----------------------------------------------------------------------- - public void testCopy_charArrayToOutputStream() throws Exception { - String str = new String(inData, "US-ASCII"); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - - CopyUtils.copy(str.toCharArray(), out); - // note: this method *does* flush. - // note: we don't flush here; this IOUtils method does it for us - - assertEquals("Sizes differ", inData.length, baout.size()); - assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); - } - - public void testCopy_charArrayToOutputStream_nullEncoding() throws Exception { - String str = new String(inData, "US-ASCII"); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - - CopyUtils.copy(str.toCharArray(), out, null); - // note: this method *does* flush. - // note: we don't flush here; this IOUtils method does it for us - - assertEquals("Sizes differ", inData.length, baout.size()); - assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); - } - - public void testCopy_charArrayToOutputStream_Encoding() throws Exception { - String str = new String(inData, "US-ASCII"); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - - CopyUtils.copy(str.toCharArray(), out, "UTF16"); - // note: this method *does* flush. - // note: we don't flush here; this IOUtils method does it for us - - byte[] bytes = baout.toByteArray(); - bytes = new String(bytes, "UTF16").getBytes("US-ASCII"); - assertTrue("Content differs", Arrays.equals(inData, bytes)); - } - - public void testCopy_charArrayToWriter() throws Exception { - String str = new String(inData, "US-ASCII"); - - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - OutputStream out = new YellOnFlushAndCloseOutputStream(baout, false, true); - Writer writer = new java.io.OutputStreamWriter(baout, "US-ASCII"); - - CopyUtils.copy(str.toCharArray(), writer); - writer.flush(); - - assertEquals("Sizes differ", inData.length, baout.size()); - assertTrue("Content differs", Arrays.equals(inData, baout.toByteArray())); - } - -} +} // CopyUtilsTest 1.9 +143 -241 jakarta-commons/io/src/java/org/apache/commons/io/CopyUtils.java Index: CopyUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/io/src/java/org/apache/commons/io/CopyUtils.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- CopyUtils.java 31 Jul 2004 10:40:47 -0000 1.8 +++ CopyUtils.java 13 Aug 2004 23:51:41 -0000 1.9 @@ -16,7 +16,6 @@ package org.apache.commons.io; import java.io.ByteArrayInputStream; -import java.io.CharArrayReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -87,9 +86,6 @@ * * 7 copy byte[] Writer 3 * 8 copy byte[] OutputStream (trivial) - * - * 9 copy char[] OutputStream 4 - * 10 copy char[] Writer (trivial) * </pre> * * <p>Note that only the first two methods shuffle bytes; the rest use these @@ -102,13 +98,15 @@ * @author Peter Donald * @author Jeff Turner * @author Matthew Hawthorne - * @author Stephen Colebourne * @version $Id$ + * @deprecated Use IOUtils. Will be removed in 2.0. + * Methods renamed to IOUtils.write() or IOUtils.copy(). + * Null handling behaviour changed in IOUtils (null data does not throw NullPointerException). */ public class CopyUtils { /** - * The default buffer size to use. + * The name says it all. */ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; @@ -117,68 +115,75 @@ */ public CopyUtils() {} - // from byte[] - //----------------------------------------------------------------------- + // ---------------------------------------------------------------- + // byte[] -> OutputStream + // ---------------------------------------------------------------- + /** * Copy bytes from a <code>byte[]</code> to an <code>OutputStream</code>. - * - * @param input the byte array to read from, do not modify during output - * @param output the <code>OutputStream</code> to write to - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs + * @param input the byte array to read from + * @param output the <code>OutputStream</code> to write to + * @throws IOException In case of an I/O problem */ - public static void copy(byte[] input, OutputStream output) throws IOException { + public static void copy(byte[] input, OutputStream output) + throws IOException { output.write(input); } + // ---------------------------------------------------------------- + // byte[] -> Writer + // ---------------------------------------------------------------- + /** - * Copy bytes from a <code>byte[]</code> to chars on a <code>Writer</code> - * using the default character encoding of the platform. - * <p> - * This method uses [EMAIL PROTECTED] ByteArrayInputStream} and [EMAIL PROTECTED] InputStreamReader}. - * - * @param input the byte array to read from, do not modify during output - * @param output the <code>Writer</code> to write to - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs + * Copy and convert bytes from a <code>byte[]</code> to chars on a + * <code>Writer</code>. + * The platform's default encoding is used for the byte-to-char conversion. + * @param input the byte array to read from + * @param output the <code>Writer</code> to write to + * @throws IOException In case of an I/O problem */ - public static void copy(byte[] input, Writer output) throws IOException { + public static void copy(byte[] input, Writer output) + throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(input); copy(in, output); } + /** - * Copy bytes from a <code>byte[]</code> to chars on a <code>Writer</code> - * using the specified character encoding. - * <p> - * Character encoding names can be found at - * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. - * <p> - * This method uses [EMAIL PROTECTED] ByteArrayInputStream} and [EMAIL PROTECTED] InputStreamReader}. - * - * @param input the byte array to read from, do not modify during output - * @param output the <code>Writer</code> to write to - * @param encoding the encoding to use, null means platform default - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(byte[] input, Writer output, String encoding) throws IOException { + * Copy and convert bytes from a <code>byte[]</code> to chars on a + * <code>Writer</code>, using the specified encoding. + * @param input the byte array to read from + * @param output the <code>Writer</code> to write to + * @param encoding The name of a supported character encoding. See the + * <a href="http://www.iana.org/assignments/character-sets">IANA + * Charset Registry</a> for a list of valid encoding types. + * @throws IOException In case of an I/O problem + */ + public static void copy( + byte[] input, + Writer output, + String encoding) + throws IOException { ByteArrayInputStream in = new ByteArrayInputStream(input); copy(in, output, encoding); } - // from InputStream - //----------------------------------------------------------------------- + + // ---------------------------------------------------------------- + // Core copy methods + // ---------------------------------------------------------------- + /** * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>. - * - * @param input the <code>InputStream</code> to read from - * @param output the <code>OutputStream</code> to write to + * @param input the <code>InputStream</code> to read from + * @param output the <code>OutputStream</code> to write to * @return the number of bytes copied - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs + * @throws IOException In case of an I/O problem */ - public static int copy(InputStream input, OutputStream output) throws IOException { + public static int copy( + InputStream input, + OutputStream output) + throws IOException { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int count = 0; int n = 0; @@ -189,110 +194,21 @@ return count; } - /** - * Copy bytes from an <code>InputStream</code> to chars on a <code>Writer</code> - * using the default character encoding of the platform. - * <p> - * This method uses [EMAIL PROTECTED] InputStreamReader}. - * - * @param input the <code>InputStream</code> to read from - * @param output the <code>Writer</code> to write to - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(InputStream input, Writer output) throws IOException { - InputStreamReader in = new InputStreamReader(input); - copy(in, output); - } + // ---------------------------------------------------------------- + // Reader -> Writer + // ---------------------------------------------------------------- /** - * Copy bytes from an <code>InputStream</code> to chars on a <code>Writer</code> - * using the specified character encoding. - * <p> - * Character encoding names can be found at - * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. - * <p> - * This method uses [EMAIL PROTECTED] InputStreamReader}. - * - * @param input the <code>InputStream</code> to read from - * @param output the <code>Writer</code> to write to - * @param encoding the encoding to use, null means platform default - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(InputStream input, Writer output, String encoding) throws IOException { - if (encoding == null) { - copy(input, output); - } else { - InputStreamReader in = new InputStreamReader(input, encoding); - copy(in, output); - } - } - - // from char[] - //----------------------------------------------------------------------- - /** - * Copy chars from a <code>char[]</code> to a <code>Writer</code> - * using the default character encoding of the platform. - * <p> - * This method uses [EMAIL PROTECTED] CharArrayReader}. - * - * @param input the char array to read from, do not modify during output - * @param output the <code>Writer</code> to write to - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(char[] input, Writer output) throws IOException { - output.write(input); - } - - /** - * Copy chars from a <code>char[]</code> to bytes on an <code>OutputStream</code>. - * <p> - * This method uses [EMAIL PROTECTED] CharArrayReader} and [EMAIL PROTECTED] OutputStreamWriter}. - * - * @param input the char array to read from, do not modify during output - * @param output the <code>OutputStream</code> to write to - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(char[] input, OutputStream output) throws IOException { - CharArrayReader in = new CharArrayReader(input); - copy(in, output); - } - - /** - * Copy chars from a <code>char[]</code> to bytes on an <code>OutputStream</code> - * using the specified character encoding. - * <p> - * Character encoding names can be found at - * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. - * <p> - * This method uses [EMAIL PROTECTED] CharArrayReader} and [EMAIL PROTECTED] OutputStreamWriter}. - * - * @param input the char array to read from, do not modify during output - * @param output the <code>OutputStream</code> to write to - * @param encoding the encoding to use, null means platform default - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(char[] input, OutputStream output, String encoding) throws IOException { - CharArrayReader in = new CharArrayReader(input); - copy(in, output, encoding); - } - - // from Reader - //----------------------------------------------------------------------- - /** * Copy chars from a <code>Reader</code> to a <code>Writer</code>. - * - * @param input the <code>Reader</code> to read from - * @param output the <code>Writer</code> to write to + * @param input the <code>Reader</code> to read from + * @param output the <code>Writer</code> to write to * @return the number of characters copied - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs + * @throws IOException In case of an I/O problem */ - public static int copy(Reader input, Writer output) throws IOException { + public static int copy( + Reader input, + Writer output) + throws IOException { char[] buffer = new char[DEFAULT_BUFFER_SIZE]; int count = 0; int n = 0; @@ -303,82 +219,82 @@ return count; } - /** - * Copy chars from a <code>Reader</code> to bytes on an <code>OutputStream</code> - * using the default character encoding of the platform, and calling flush. - * <p> - * Due to the implementation of OutputStreamWriter, this method performs a flush. - * <p> - * This method uses [EMAIL PROTECTED] OutputStreamWriter}. - * - * @param input the <code>Reader</code> to read from - * @param output the <code>OutputStream</code> to write to - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(Reader input, OutputStream output) throws IOException { - OutputStreamWriter out = new OutputStreamWriter(output); - copy(input, out); - // XXX Unless anyone is planning on rewriting OutputStreamWriter, we have to flush here. - out.flush(); + // ---------------------------------------------------------------- + // InputStream -> Writer + // ---------------------------------------------------------------- + + /** + * Copy and convert bytes from an <code>InputStream</code> to chars on a + * <code>Writer</code>. + * The platform's default encoding is used for the byte-to-char conversion. + * @param input the <code>InputStream</code> to read from + * @param output the <code>Writer</code> to write to + * @throws IOException In case of an I/O problem + */ + public static void copy( + InputStream input, + Writer output) + throws IOException { + InputStreamReader in = new InputStreamReader(input); + copy(in, output); } /** - * Copy chars from a <code>Reader</code> to bytes on an <code>OutputStream</code> - * using the specified character encoding, and calling flush. - * <p> - * Character encoding names can be found at - * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. - * <p> - * Due to the implementation of OutputStreamWriter, this method performs a flush. - * <p> - * This method uses [EMAIL PROTECTED] OutputStreamWriter}. - * - * @param input the <code>Reader</code> to read from - * @param output the <code>OutputStream</code> to write to - * @param encoding the encoding to use, null means platform default - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(Reader input, OutputStream output, String encoding) throws IOException { - if (encoding == null) { - copy(input, output); - } else { - OutputStreamWriter out = new OutputStreamWriter(output, encoding); - copy(input, out); - // XXX Unless anyone is planning on rewriting OutputStreamWriter, we have to flush here. - out.flush(); - } + * Copy and convert bytes from an <code>InputStream</code> to chars on a + * <code>Writer</code>, using the specified encoding. + * @param input the <code>InputStream</code> to read from + * @param output the <code>Writer</code> to write to + * @param encoding The name of a supported character encoding. See the + * <a href="http://www.iana.org/assignments/character-sets">IANA + * Charset Registry</a> for a list of valid encoding types. + * @throws IOException In case of an I/O problem + */ + public static void copy( + InputStream input, + Writer output, + String encoding) + throws IOException { + InputStreamReader in = new InputStreamReader(input, encoding); + copy(in, output); } - // from String - //----------------------------------------------------------------------- + + // ---------------------------------------------------------------- + // Reader -> OutputStream + // ---------------------------------------------------------------- + /** - * Copy chars from a <code>String</code> to a <code>Writer</code>. - * - * @param input the <code>String</code> to read from - * @param output the <code>Writer</code> to write to - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(String input, Writer output) throws IOException { - output.write(input); + * Serialize chars from a <code>Reader</code> to bytes on an + * <code>OutputStream</code>, and flush the <code>OutputStream</code>. + * @param input the <code>Reader</code> to read from + * @param output the <code>OutputStream</code> to write to + * @throws IOException In case of an I/O problem + */ + public static void copy( + Reader input, + OutputStream output) + throws IOException { + OutputStreamWriter out = new OutputStreamWriter(output); + copy(input, out); + // XXX Unless anyone is planning on rewriting OutputStreamWriter, we have to flush here. + out.flush(); } + // ---------------------------------------------------------------- + // String -> OutputStream + // ---------------------------------------------------------------- + /** - * Copy chars from a <code>String</code> to bytes on an <code>OutputStream</code> - * using the default character encoding of the platform, and calling flush. - * <p> - * Due to the implementation of OutputStreamWriter, this method performs a flush. - * <p> - * This method uses [EMAIL PROTECTED] StringReader} and [EMAIL PROTECTED] OutputStreamWriter}. - * - * @param input the <code>String</code> to read from - * @param output the <code>OutputStream</code> to write to - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(String input, OutputStream output) throws IOException { + * Serialize chars from a <code>String</code> to bytes on an <code>OutputStream</code>, and + * flush the <code>OutputStream</code>. + * @param input the <code>String</code> to read from + * @param output the <code>OutputStream</code> to write to + * @throws IOException In case of an I/O problem + */ + public static void copy( + String input, + OutputStream output) + throws IOException { StringReader in = new StringReader(input); OutputStreamWriter out = new OutputStreamWriter(output); copy(in, out); @@ -386,33 +302,19 @@ out.flush(); } + // ---------------------------------------------------------------- + // String -> Writer + // ---------------------------------------------------------------- + /** - * Copy chars from a <code>String</code> to bytes on an <code>OutputStream</code> - * using the specified character encoding, and calling flush. - * <p> - * Character encoding names can be found at - * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. - * <p> - * Due to the implementation of OutputStreamWriter, this method performs a flush. - * <p> - * This method uses [EMAIL PROTECTED] StringReader} and [EMAIL PROTECTED] OutputStreamWriter}. - * - * @param input the <code>String</code> to read from - * @param output the <code>OutputStream</code> to write to - * @param encoding the encoding to use, null means platform default - * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs - */ - public static void copy(String input, OutputStream output, String encoding) throws IOException { - if (encoding == null) { - copy(input, output); - } else { - StringReader in = new StringReader(input); - OutputStreamWriter out = new OutputStreamWriter(output, encoding); - copy(in, out); - // XXX Unless anyone is planning on rewriting OutputStreamWriter, we have to flush here. - out.flush(); - } + * Copy chars from a <code>String</code> to a <code>Writer</code>. + * @param input the <code>String</code> to read from + * @param output the <code>Writer</code> to write to + * @throws IOException In case of an I/O problem + */ + public static void copy(String input, Writer output) + throws IOException { + output.write(input); } -} +} // CopyUtils 1.37 +3 -3 jakarta-commons/io/src/java/org/apache/commons/io/FileUtils.java Index: FileUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/io/src/java/org/apache/commons/io/FileUtils.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- FileUtils.java 24 Jul 2004 09:58:41 -0000 1.36 +++ FileUtils.java 13 Aug 2004 23:51:41 -0000 1.37 @@ -456,7 +456,7 @@ try { FileOutputStream output = new FileOutputStream(destination); try { - CopyUtils.copy(input, output); + IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(output); } @@ -514,7 +514,7 @@ try { FileOutputStream output = new FileOutputStream(destination); try { - CopyUtils.copy(input, output); + IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(output); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]