Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1.0-rc-1, 1.8.9, 2.0.7
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      We could add the following methods to GString:

      byte[] getBytes(Charset charset)
      byte[] getBytes()
      

      which could just call toString().getBytes()

        Activity

        Hide
        blackdrag blackdrag added a comment - - edited

        if they are methods on String, then at least from Groovy they should work without adding anything. And I just checked, this works too. So what is this about?

        Show
        blackdrag blackdrag added a comment - - edited if they are methods on String, then at least from Groovy they should work without adding anything. And I just checked, this works too. So what is this about?
        Hide
        Paul King added a comment -

        The original use case was from Grails (within a service I think) but I think it is a Groovy issue:

        def s = "Hello Oct 18, 2012 4:54:10 AM"
        println s.bytes.encodeBase64()
        // => SGVsbG8gT2N0IDE4LCAyMDEyIDQ6NTQ6MTAgQU0=
        def gs = "Hello ${new Date()}"
        println gs.bytes.encodeBase64()
        // => groovy.lang.MissingPropertyException: No such property: bytes for class: org.codehaus.groovy.runtime.GStringImpl
        
        Show
        Paul King added a comment - The original use case was from Grails (within a service I think) but I think it is a Groovy issue: def s = "Hello Oct 18, 2012 4:54:10 AM" println s.bytes.encodeBase64() // => SGVsbG8gT2N0IDE4LCAyMDEyIDQ6NTQ6MTAgQU0= def gs = "Hello ${ new Date()}" println gs.bytes.encodeBase64() // => groovy.lang.MissingPropertyException: No such property: bytes for class: org.codehaus.groovy.runtime.GStringImpl
        Hide
        Pascal Schumacher added a comment -

        I created a pull request https://github.com/groovy/groovy-core/pull/99 for this.

        The method "byte[] getBytes(Charset charset)" isn't in JDK 1.5 so I added "byte[] getBytes(String charset)" instead.

        Show
        Pascal Schumacher added a comment - I created a pull request https://github.com/groovy/groovy-core/pull/99 for this. The method "byte[] getBytes(Charset charset)" isn't in JDK 1.5 so I added "byte[] getBytes(String charset)" instead.
        Hide
        blackdrag blackdrag added a comment -

        pull request applied

        Show
        blackdrag blackdrag added a comment - pull request applied

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Paul King
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: