Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3692

specify encoding for File's combinient methods (eachLine,..)

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.6.8, 1.7.1
    • groovy-jdk
    • None

    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.

      Attachments

        Activity

          People

            paulk Paul King
            uehaj UEHARA Junji
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: