Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Number of attachments :
Description
In File's some convenient methods like File#eachLine(), File#splitEachLine() and others, there is no way to specify the encoding for reading.
For example, there is no 'File#eachLine(String charSet, Closure c)' method.
Of cource, we can write:
new InputStreamReader(new FileInputStream(new File("file_to_read.txt")), charSet).eachLine { .. }
but this is not so groovy.
My proposal is, to add encoding() method to java.io.File as a GDK enhancement method, which can be used like:
new File(args[0]).encoding("utf-8").eachLine { println it }
As reference, if write it by EMC, the definition of method encoding is like:
File.metaClass.encoding = { cs ->
new InputStreamReader(new FileInputStream(delegate), cs)
}
GDK of java.io.InputStreamReader has equivalents each* methods, this is enough.
I found File#newReader(String enc), and this is same as my encoding() method .
so i would like to modify my proposal.
My new proposal is to add:
Object eachLine(String charset, Closure closure)
Object eachLine(String charset, int firstLine, Closure closure)
to File class as GDK methods.
In addition ,compare File/InputStream/URL methods, following method set are slightly different:
I think those should basically be the same set.