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

eachLine and splitEachLine work without encoding

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.5
    • 1.5.6, 1.6-beta-1
    • None
    • None

    Description

      several methods where added named eachLine and splitEachLine. But on InputStream no encoding is given, thus a InputStreamReader created there uses the default encoding, which might be wrong in many case. I personally would add the methods with the encoding variant and remove the ones without encoding for InputStream and URL. not using an encoding makes sense for String, because the encoding is already done then, in fact using an ecoding there could be seen as wrong. But not using an encoding on InputStream is wrong too. It is not portable and will kick you later. This means:

      eachLine:

      InputStream.eachLine(Closure) --> should be removed
      InputStream.eachLine(String encoding, Closure) --> should be added
      URL.eachLine(Closure) --> should be removed
      URL.eachLine(String encoding, Closure) --> could be added, but I would prefer:
      URL.toInputStream() ---> I prefer that, because then eachLine from InputStream can be used

      splitEachLine:

      InputStream.splitEachLine(String sep, Closure closure) --> should be removed
      InputStream.splitEachLine(String encoding, String sep, Closure closure) --> should be added
      URL.splitEachLine(String sep, Closure closure) --> should be removed
      URL.splitEachLine(String encoding, String sep, Closure closure) --> could be added, again I prefer URL.toInputStream().. or URL.input

      then all these each method should not return void, instead they should return what the closure returns the last time it was called. This allows writing a collecting closure which has to be added.. something like this

      class Collector extends Closure {
        def closure
        def values = []
        def doCall(Object[] args) {
          if (closure!=null) closure(*args)
          values << args
          return values
        }
      }
      

      Attachments

        Activity

          People

            paulk Paul King
            blackdrag Jochen Theodorou
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: