You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2012/04/16 15:28:49 UTC

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

Author: ggregory
Date: Mon Apr 16 13:28:49 2012
New Revision: 1326609

URL: http://svn.apache.org/viewvc?rev=1326609&view=rev
Log:
[IO-324] Add Charset sister APIs to method that take a String charset name.

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.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=1326609&r1=1326608&r2=1326609&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Mon Apr 16 13:28:49 2012
@@ -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.4" date="2012-TDB-TDB" description="">
+      <action issue="IO-324" dev="ggregory" type="fix" due-to="raviprak">
+        Add missing Charset sister APIs to method that take a String charset name.
+      </action>            
       <action issue="IO-319" dev="ggregory" type="fix" due-to="raviprak">
         FileUtils.sizeOfDirectory follows symbolic links.
       </action>            

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java?rev=1326609&r1=1326608&r2=1326609&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java Mon Apr 16 13:28:49 2012
@@ -1821,6 +1821,23 @@ public class FileUtils {
      * @param encoding  the encoding to use, {@code null} means platform default
      * @throws IOException in case of an I/O error
      * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
+     * @since 2.4
+     */
+    public static void writeStringToFile(File file, String data, Charset encoding) throws IOException {
+        writeStringToFile(file, data, encoding, false);
+    }
+
+    /**
+     * Writes a String to a file creating the file if it does not exist.
+     *
+     * NOTE: As from v1.3, the parent directories of the file will be created
+     * if they do not exist.
+     *
+     * @param file  the file to write
+     * @param data  the content to write to the file
+     * @param encoding  the encoding to use, {@code null} means platform default
+     * @throws IOException in case of an I/O error
+     * @throws java.io.UnsupportedEncodingException if the encoding is not supported by the VM
      */
     public static void writeStringToFile(File file, String data, String encoding) throws IOException {
         writeStringToFile(file, data, encoding, false);



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

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Apr 18, 2012 at 9:34 AM, Jörg Schaible
<Jo...@scalaris.com>wrote:

> Gary Gregory wrote:
>
> > On Wed, Apr 18, 2012 at 12:38 AM, Stefan Bodewig <bo...@apache.org>
> > wrote:
> >
> >> On 2012-04-16, <gg...@apache.org> wrote:
> >>
> >> > [IO-324] Add Charset sister APIs to method that take a String charset
> >> name.
> >>
> >> The new methods cause problems for people who pass in null for the
> >> charset as they want the platform's system default.  The compiler
> >> doesn't know which of the writeStringToFile methods to pick if the third
> >> param is null.
> >>
> >
> > You are correct. See the release notes:
> >
> > Compatibility with 2.2 and 1.4:
> > Binary compatible: Yes.
> > Source compatible: No, see the rare case in
> > https://issues.apache.org/jira/browse/IO-318.
> > Semantic compatible: No, see the rare case in
> > https://issues.apache.org/jira/browse/IO-318.
> >
> > There are two solutions if you want to use the latest [io], as noted in
> > the Jira:
> >
> > - type-cast the charset to String to Charset, or
> > - use the API that does not have a charset.
>
> We could add a writeStringToFile() method without parameter. No need for a
> null value, no need for the cast.
>

The API is already there :)

Gary

>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

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

Posted by Jörg Schaible <Jo...@scalaris.com>.
Gary Gregory wrote:

> On Wed, Apr 18, 2012 at 12:38 AM, Stefan Bodewig <bo...@apache.org>
> wrote:
> 
>> On 2012-04-16, <gg...@apache.org> wrote:
>>
>> > [IO-324] Add Charset sister APIs to method that take a String charset
>> name.
>>
>> The new methods cause problems for people who pass in null for the
>> charset as they want the platform's system default.  The compiler
>> doesn't know which of the writeStringToFile methods to pick if the third
>> param is null.
>>
> 
> You are correct. See the release notes:
> 
> Compatibility with 2.2 and 1.4:
> Binary compatible: Yes.
> Source compatible: No, see the rare case in
> https://issues.apache.org/jira/browse/IO-318.
> Semantic compatible: No, see the rare case in
> https://issues.apache.org/jira/browse/IO-318.
> 
> There are two solutions if you want to use the latest [io], as noted in
> the Jira:
> 
> - type-cast the charset to String to Charset, or
> - use the API that does not have a charset.

We could add a writeStringToFile() method without parameter. No need for a 
null value, no need for the cast.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


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

Posted by Jörg Schaible <jo...@gmx.de>.
Bill Barker wrote:

[snip]
> 
> As Stefan pointed out at the beginning of this thread, it isn't a drop in
> replacement. The [io] team has deliberately broken all backwards
> compatibility. 

... and as we pointed out, this has absolutely *no* effect on already 
compiled code. And we care *a lot* for this. And therefore it *is* a drop in 
replacement.

In case of FileUtils, you can use for compilation now either the method 
without the encoding parameter or by casting for the corner case where you 
explicitly pass null as a constant.

> That is why I'm sticking to my statement that will never
> use
> [io] ever again in my day job, and will recommend guava instead.

Oh, well, then you should avoid also to use the JDK at all. Similar 
situation arise for

new StringBuffer(null);

this compiles with JDK 1.4.2, but is ambiguous in JDK 1.5.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


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

Posted by Bill Barker <bi...@verizon.net>.

-----Original Message----- 
From: JörgSchaible
Sent: Friday, April 20, 2012 6:54 AM
To: dev@commons.apache.org
Subject: Re: svn commit: r1326609 - in /commons/proper/io/trunk/src: 
changes/changes.xml main/java/org/apache/commons/io/FileUtils.java

Bill Barker wrote:

>>
>>
>> -----Original Message-----
>> From: Gary Gregory
>> Sent: Wednesday, April 18, 2012 6:15 AM
>> To: Commons Developers List
>> Subject: Re: svn commit: r1326609 - in /commons/proper/io/trunk/src:
>> changes/changes.xml main/java/org/apache/commons/io/FileUtils.java
>>
>> On Wed, Apr 18, 2012 at 12:38 AM, Stefan Bodewig <bo...@apache.org>
>> wrote:
>>
>>>> On 2012-04-16, <gg...@apache.org> wrote:
>>>>
>>>> > [IO-324] Add Charset sister APIs to method that take a String charset
>>>> name.
>>>>
>>>> The new methods cause problems for people who pass in null for the
>>>> charset as they want the platform's system default.  The compiler
>>>> doesn't know which of the writeStringToFile methods to pick if the 
>>>> third
>>>> param is null.
>>>>
>>>
>>>You are correct. See the release notes:
>>>
>>>Compatibility with 2.2 and 1.4:
>>>Binary compatible: Yes.>
>>>Source compatible: No, see the rare case in
>>>https://issues.apache.org/jira/browse/IO-318.
>>>Semantic compatible: No, see the rare case in
>>>https://issues.apache.org/jira/browse/IO-318.
>>>
>>>There are two solutions if you want to use the latest [io], as noted in
>>>the Jira:
>>>
>>>- type-cast the charset to String to Charset, or
>>>- use the API that does not have a charset.
>>>
>>>Thank you,
>>>Gary
>>>
>>
>> And this is exactly why I wouldn't touch commons-io for any new project 
>> in
>> my day job. I would choose guava instead 99 times out of 100.  If you 
>> want
>> to kill [io] this way, then I will continue to not vote on it. But IMHO,
>> it isn't a viable project anymore against guava without more
>> considerations for backwards compatibility.
>
>
>? What more can you expect than taking the new jar and replace an old one
>and your application simply runs?
>

As Stefan pointed out at the beginning of this thread, it isn't a drop in 
replacement. The [io] team has deliberately broken all backwards 
compatibility. That is why I'm sticking to my statement that will never use 
[io] ever again in my day job, and will recommend guava instead.

>- Jörg
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


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

Posted by Jörg Schaible <jo...@gmx.de>.
Bill Barker wrote:

> 
> 
> -----Original Message-----
> From: Gary Gregory
> Sent: Wednesday, April 18, 2012 6:15 AM
> To: Commons Developers List
> Subject: Re: svn commit: r1326609 - in /commons/proper/io/trunk/src:
> changes/changes.xml main/java/org/apache/commons/io/FileUtils.java
> 
> On Wed, Apr 18, 2012 at 12:38 AM, Stefan Bodewig <bo...@apache.org>
> wrote:
> 
>>> On 2012-04-16, <gg...@apache.org> wrote:
>>>
>>> > [IO-324] Add Charset sister APIs to method that take a String charset
>>> name.
>>>
>>> The new methods cause problems for people who pass in null for the
>>> charset as they want the platform's system default.  The compiler
>>> doesn't know which of the writeStringToFile methods to pick if the third
>>> param is null.
>>>
>>
>>You are correct. See the release notes:
>>
>>Compatibility with 2.2 and 1.4:
>>Binary compatible: Yes.
>>Source compatible: No, see the rare case in
>>https://issues.apache.org/jira/browse/IO-318.
>>Semantic compatible: No, see the rare case in
>>https://issues.apache.org/jira/browse/IO-318.
>>
>>There are two solutions if you want to use the latest [io], as noted in
>>the Jira:
>>
>>- type-cast the charset to String to Charset, or
>>- use the API that does not have a charset.
>>
>>Thank you,
>>Gary
>>
> 
> And this is exactly why I wouldn't touch commons-io for any new project in
> my day job. I would choose guava instead 99 times out of 100.  If you want
> to kill [io] this way, then I will continue to not vote on it. But IMHO,
> it isn't a viable project anymore against guava without more
> considerations for backwards compatibility.


?!? What more can you expect than taking the new jar and replace an old one 
and your application simply runs?

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


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

Posted by Bill Barker <bi...@verizon.net>.

-----Original Message----- 
From: Gary Gregory
Sent: Wednesday, April 18, 2012 6:15 AM
To: Commons Developers List
Subject: Re: svn commit: r1326609 - in /commons/proper/io/trunk/src: 
changes/changes.xml main/java/org/apache/commons/io/FileUtils.java

On Wed, Apr 18, 2012 at 12:38 AM, Stefan Bodewig <bo...@apache.org> wrote:

>> On 2012-04-16, <gg...@apache.org> wrote:
>>
>> > [IO-324] Add Charset sister APIs to method that take a String charset
>> name.
>>
>> The new methods cause problems for people who pass in null for the
>> charset as they want the platform's system default.  The compiler
>> doesn't know which of the writeStringToFile methods to pick if the third
>> param is null.
>>
>
>You are correct. See the release notes:
>
>Compatibility with 2.2 and 1.4:
>Binary compatible: Yes.
>Source compatible: No, see the rare case in
>https://issues.apache.org/jira/browse/IO-318.
>Semantic compatible: No, see the rare case in
>https://issues.apache.org/jira/browse/IO-318.
>
>There are two solutions if you want to use the latest [io], as noted in the
>Jira:
>
>- type-cast the charset to String to Charset, or
>- use the API that does not have a charset.
>
>Thank you,
>Gary
>

And this is exactly why I wouldn't touch commons-io for any new project in 
my day job. I would choose guava instead 99 times out of 100.  If you want 
to kill [io] this way, then I will continue to not vote on it. But IMHO, it 
isn't a viable project anymore against guava without more considerations for 
backwards compatibility.



>> See
>> <
>> http://vmgump.apache.org/gump/public/google-docbkx/google-docbkx-maven-builder/gump_work/build_google-docbkx_google-docbkx-maven-builder.html
>> >
>>
> >The code that was broken is
>> <
>> http://docbkx-tools.googlecode.com/svn/trunk/docbkx-builder-maven-plugin/src/main/java/com/agilejava/maven/docbkx/GeneratorMojo.java
>> >
>>
>> Stefan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
>-- 
>E-Mail: garydgregory@gmail.com | ggregory@apache.org
>JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
>Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
>Blog: http://garygregory.wordpress.com
>Home: http://garygregory.com/
>Tweet! http://twitter.com/GaryGregory 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


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

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Apr 18, 2012 at 12:38 AM, Stefan Bodewig <bo...@apache.org> wrote:

> On 2012-04-16, <gg...@apache.org> wrote:
>
> > [IO-324] Add Charset sister APIs to method that take a String charset
> name.
>
> The new methods cause problems for people who pass in null for the
> charset as they want the platform's system default.  The compiler
> doesn't know which of the writeStringToFile methods to pick if the third
> param is null.
>

You are correct. See the release notes:

Compatibility with 2.2 and 1.4:
Binary compatible: Yes.
Source compatible: No, see the rare case in
https://issues.apache.org/jira/browse/IO-318.
Semantic compatible: No, see the rare case in
https://issues.apache.org/jira/browse/IO-318.

There are two solutions if you want to use the latest [io], as noted in the
Jira:

- type-cast the charset to String to Charset, or
- use the API that does not have a charset.

Thank you,
Gary


> See
> <
> http://vmgump.apache.org/gump/public/google-docbkx/google-docbkx-maven-builder/gump_work/build_google-docbkx_google-docbkx-maven-builder.html
> >
>
> The code that was broken is
> <
> http://docbkx-tools.googlecode.com/svn/trunk/docbkx-builder-maven-plugin/src/main/java/com/agilejava/maven/docbkx/GeneratorMojo.java
> >
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

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

Posted by Stefan Bodewig <bo...@apache.org>.
On 2012-04-16, <gg...@apache.org> wrote:

> [IO-324] Add Charset sister APIs to method that take a String charset name.

The new methods cause problems for people who pass in null for the
charset as they want the platform's system default.  The compiler
doesn't know which of the writeStringToFile methods to pick if the third
param is null.

See
<http://vmgump.apache.org/gump/public/google-docbkx/google-docbkx-maven-builder/gump_work/build_google-docbkx_google-docbkx-maven-builder.html>

The code that was broken is
<http://docbkx-tools.googlecode.com/svn/trunk/docbkx-builder-maven-plugin/src/main/java/com/agilejava/maven/docbkx/GeneratorMojo.java>

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


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

Posted by Stefan Bodewig <bo...@apache.org>.
On 2012-04-16, <gg...@apache.org> wrote:

> [IO-324] Add Charset sister APIs to method that take a String charset name.

The new methods cause problems for people who pass in null for the
charset as they want the platform's system default.  The compiler
doesn't know which of the writeStringToFile methods to pick if the third
param is null.

See
<http://vmgump.apache.org/gump/public/google-docbkx/google-docbkx-maven-builder/gump_work/build_google-docbkx_google-docbkx-maven-builder.html>

The code that was broken is
<http://docbkx-tools.googlecode.com/svn/trunk/docbkx-builder-maven-plugin/src/main/java/com/agilejava/maven/docbkx/GeneratorMojo.java>

Stefan