You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/04/17 15:11:32 UTC

svn commit: r1468894 - in /commons/proper/io/trunk/src: changes/changes.xml main/java/org/apache/commons/io/CopyUtils.java

Author: sebb
Date: Wed Apr 17 13:11:32 2013
New Revision: 1468894

URL: http://svn.apache.org/r1468894
Log:
IO-314 Deprecate and then remove all methods that use the default encoding

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/CopyUtils.java

Modified: commons/proper/io/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1468894&r1=1468893&r2=1468894&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Wed Apr 17 13:11:32 2013
@@ -47,6 +47,9 @@ The <action> type attribute can be add,u
   <body>
     <!-- The release date is the date RC is cut -->
     <release version="2.5" date="2013-??-??" description="New features and bug fixes.">    
+      <action issue="IO-314" dev="sebb" type="fix">
+        Deprecate and then remove all methods that use the default encoding
+      </action>            
       <action issue="IO-338" dev="sebb" type="fix">
         When a file is rotated, finish reading previous file prior to starting new one
       </action>            

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/CopyUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/CopyUtils.java?rev=1468894&r1=1468893&r2=1468894&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/CopyUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/CopyUtils.java Wed Apr 17 13:11:32 2013
@@ -25,6 +25,7 @@ import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.Writer;
+import java.nio.charset.Charset;
 
 /**
  * This class provides static utility methods for buffered
@@ -147,7 +148,9 @@ public class CopyUtils {
      * @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
+     * @deprecated use {@link #copy(byte[], Writer, String)} instead
      */
+    @Deprecated
     public static void copy(final byte[] input, final Writer output)
             throws IOException {
         final ByteArrayInputStream in = new ByteArrayInputStream(input);
@@ -237,12 +240,15 @@ public class CopyUtils {
      * @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
+     * @deprecated use {@link #copy(InputStream, Writer, String)} instead
      */
+    @Deprecated
     public static void copy(
             final InputStream input,
             final Writer output)
                 throws IOException {
-        final InputStreamReader in = new InputStreamReader(input);
+        // make explicit the dependency on the default encoding
+        final InputStreamReader in = new InputStreamReader(input, Charset.defaultCharset());
         copy(in, output);
     }
 
@@ -273,15 +279,39 @@ public class CopyUtils {
     /**
      * Serialize chars from a <code>Reader</code> to bytes on an
      * <code>OutputStream</code>, and flush the <code>OutputStream</code>.
+     * Uses the default platform encoding.
      * @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
+     * @deprecated use {@link #copy(Reader, OutputStream, String)} instead
      */
+    @Deprecated
     public static void copy(
             final Reader input,
             final OutputStream output)
                 throws IOException {
-        final OutputStreamWriter out = new OutputStreamWriter(output);
+        // make explicit the dependency on the default encoding
+        final OutputStreamWriter out = new OutputStreamWriter(output, Charset.defaultCharset());
+        copy(input, out);
+        // XXX Unless anyone is planning on rewriting OutputStreamWriter, we
+        // have to flush here.
+        out.flush();
+    }
+
+    /**
+     * 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
+     * @since 2.5
+     */
+    public static void copy(
+            final Reader input,
+            final OutputStream output,
+            final String encoding)
+                throws IOException {
+        final OutputStreamWriter out = new OutputStreamWriter(output, encoding);
         copy(input, out);
         // XXX Unless anyone is planning on rewriting OutputStreamWriter, we
         // have to flush here.
@@ -296,16 +326,42 @@ public class CopyUtils {
      * Serialize chars from a <code>String</code> to bytes on an
      * <code>OutputStream</code>, and
      * flush the <code>OutputStream</code>.
+     * Uses the platform default encoding.
      * @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
+     * @deprecated use {@link #copy(String, OutputStream, String)} instead
      */
+    @Deprecated
     public static void copy(
             final String input,
             final OutputStream output)
                 throws IOException {
         final StringReader in = new StringReader(input);
-        final OutputStreamWriter out = new OutputStreamWriter(output);
+        // make explicit the dependency on the default encoding
+        final OutputStreamWriter out = new OutputStreamWriter(output, Charset.defaultCharset());
+        copy(in, out);
+        // XXX Unless anyone is planning on rewriting OutputStreamWriter, we
+        // have to flush here.
+        out.flush();
+    }
+
+    /**
+     * 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
+     * @since 2.5
+     */
+    public static void copy(
+            final String input,
+            final OutputStream output,
+            final String encoding)
+                throws IOException {
+        final StringReader in = new StringReader(input);
+        final OutputStreamWriter out = new OutputStreamWriter(output, encoding);
         copy(in, out);
         // XXX Unless anyone is planning on rewriting OutputStreamWriter, we
         // have to flush here.



Re: svn commit: r1468894 - in /commons/proper/io/trunk/src: changes/changes.xml main/java/org/apache/commons/io/CopyUtils.java

Posted by Emmanuel Bourg <eb...@apache.org>.
Le 17/04/2013 15:11, sebb@apache.org a écrit :

> --- commons/proper/io/trunk/src/changes/changes.xml (original)
> +++ commons/proper/io/trunk/src/changes/changes.xml Wed Apr 17 13:11:32 2013
> @@ -47,6 +47,9 @@ The <action> type attribute can be add,u
>    <body>
>      <!-- The release date is the date RC is cut -->
>      <release version="2.5" date="2013-??-??" description="New features and bug fixes.">    
> +      <action issue="IO-314" dev="sebb" type="fix">
> +        Deprecate and then remove all methods that use the default encoding
> +      </action>            
>        <action issue="IO-338" dev="sebb" type="fix">
>          When a file is rotated, finish reading previous file prior to starting new one
>        </action>  

The methods weren't removed, the description could mislead people to
believe that IO 2.5 is going to break their code.

Emmanuel Bourg