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

Allow File.append and File.leftShift to handle binary data.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.5.7, 1.6-rc-2, 1.7.0
    • 1.6-rc-2, 1.7-beta-1
    • groovy-jdk
    • None
    • Patch

    Description

      Currently, the DGM method File.append() only works for text data. File.append(Object) can technically accept an InputStream, but it assumes that both the streaming data and the output file are using the platform-default character encoding. In any other case, the data will be mangled.

      I propose creating a method File.append(InputStream) which will basically delegate to InputStream.leftShift(InputStream). This maintains backward-compatibility since all InputStreams that happen to be text will be piped through un-interpreted, which AFAIK would be identical to the current behavior of reading the stream and writing it back out using the same encoding. But in this case, if the source data is binary or happens to have an encoding that is not the platform default, it will not get mashed by a reader using the incorrect encoding. Patch is attached.

      Attachments

        1. DGM-file-leftShift.diff
          1 kB
          Tom Nichols

        Activity

          People

            tomstrummer Tom Nichols
            tomstrummer Tom Nichols
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: