8019526: (fs) Files.lines, etc without Charset parameter

Alan Bateman Alan.Bateman at oracle.com
Fri Oct 11 07:46:59 PDT 2013


The Files class defines a number of very useful methods to operate on 
text files, all of which take a Charset parameter for the charset to use 
when encoding or decoding. It's come many times that folks want variants 
of these that don't have to specify the Charset. Additionally we now 
have Files.lines, added as part of the Lambda libraries work, and a 
variant without the Charset parameter is required to use method references.

The proposal here is to define variants of each of these methods that 
use UTF-8 for encoding and decoding instead of taking a Charset 
parameter. The rational for UTF-8 is that methods that use the default 
charset are always problematic. With many platforms using UTF-8 now  
then it is less of an issue from a few years ago but still problematic 
due to the dependency on the locale. The proposal does mean an 
inconsistency with the legacy APIs but it should only be an issue if 
there is mixing of APIs without due consideration. Going forward then it 
may actually be time to consider changing the JDK's default charset to 
UTF-8 (I'm not suggesting this for JDK 8 of course, that is a mich 
bigger issue than what is proposed here and would require deeper 
consideration).

The webrev with the proposed changes is here. The updates to the Files 
class are trivial (one-liner methods), most of the changes are in the 
tests. I've expanding Henry's StreamTest to exercise Files.lines(Path) 
and also converted the BytesAndLines to TestNG. More could be done on 
the BytesAndLines but it's not critical for this patch.

http://cr.openjdk.java.net/~alanb/8019526/webrev/

Thanks,
Alan.


More information about the nio-dev mailing list