Class EncodingGroovyMethods


  • public class EncodingGroovyMethods
    extends Object
    This class defines all the encoding/decoding groovy methods which enhance the normal JDK classes when inside the Groovy environment. Static methods are used with the first parameter the destination class.
    • Constructor Detail

      • EncodingGroovyMethods

        public EncodingGroovyMethods()
    • Method Detail

      • encodeBase64

        public static Writable encodeBase64​(Byte[] data,
                                            boolean chunked)
        Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see RFC 4648.
        Parameters:
        data - Byte array to be encoded
        chunked - whether or not the Base64 encoded data should be MIME chunked
        Returns:
        object which will write the Base64 encoding of the byte array
        Since:
        1.5.1
      • encodeBase64

        public static Writable encodeBase64​(Byte[] data)
        Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see RFC 4648.
        Parameters:
        data - Byte array to be encoded
        Returns:
        object which will write the Base64 encoding of the byte array
        Since:
        1.0
      • encodeBase64

        public static Writable encodeBase64​(byte[] data,
                                            boolean chunked)
        Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see RFC 4648.
        Parameters:
        data - byte array to be encoded
        chunked - whether or not the Base64 encoded data should be MIME chunked
        Returns:
        object which will write the Base64 encoding of the byte array
        Since:
        1.5.7
      • encodeBase64

        public static Writable encodeBase64​(byte[] data)
        Produce a Writable object which writes the Base64 encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 encoding and chunking see RFC 4648.
        Parameters:
        data - byte array to be encoded
        Returns:
        object which will write the Base64 encoding of the byte array
        Since:
        1.0
      • encodeBase64Url

        public static Writable encodeBase64Url​(Byte[] data)
        Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 URL and Filename Safe encoding see RFC 4648 - Section 5 Base 64 Encoding with URL and Filename Safe Alphabet.

        The method omits padding and is equivalent to calling encodeBase64Url(Byte[], boolean) with a value of false.

        Parameters:
        data - Byte array to be encoded
        Returns:
        object which will write the Base64 URL and Filename Safe encoding of the byte array
        Since:
        2.5.0
        See Also:
        encodeBase64Url(Byte[], boolean)
      • encodeBase64Url

        public static Writable encodeBase64Url​(Byte[] data,
                                               boolean pad)
        Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 URL and Filename Safe encoding see RFC 4648 - Section 5 Base 64 Encoding with URL and Filename Safe Alphabet.
        Parameters:
        data - Byte array to be encoded
        pad - whether or not the encoded data should be padded
        Returns:
        object which will write the Base64 URL and Filename Safe encoding of the byte array
        Since:
        2.5.0
      • encodeBase64Url

        public static Writable encodeBase64Url​(byte[] data)
        Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 URL and Filename Safe encoding see RFC 4648 - Section 5 Base 64 Encoding with URL and Filename Safe Alphabet.

        The method omits padding and is equivalent to calling encodeBase64Url(byte[], boolean) with a value of false.

        Parameters:
        data - Byte array to be encoded
        Returns:
        object which will write the Base64 URL and Filename Safe encoding of the byte array
        Since:
        2.5.0
        See Also:
        encodeBase64Url(byte[], boolean)
      • encodeBase64Url

        public static Writable encodeBase64Url​(byte[] data,
                                               boolean pad)
        Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array. Calling toString() on the result returns the encoding as a String. For more information on Base64 URL and Filename Safe encoding see RFC 4648 - Section 5 Base 64 Encoding with URL and Filename Safe Alphabet.
        Parameters:
        data - Byte array to be encoded
        pad - whether or not the encoded data should be padded
        Returns:
        object which will write the Base64 URL and Filename Safe encoding of the byte array
        Since:
        2.5.0
      • decodeBase64

        public static byte[] decodeBase64​(String value)
        Decode the String from Base64 into a byte array.
        Parameters:
        value - the string to be decoded
        Returns:
        the decoded bytes as an array
        Since:
        1.0
      • decodeBase64Url

        public static byte[] decodeBase64Url​(String value)
        Decodes a Base64 URL and Filename Safe encoded String into a byte array.
        Parameters:
        value - the string to be decoded
        Returns:
        the decoded bytes as an array
        Since:
        2.5.0
      • encodeHex

        public static Writable encodeHex​(Byte[] data)
        Produces a Writable that writes the hex encoding of the Byte[]. Calling toString() on this Writable returns the hex encoding as a String. The hex encoding includes two characters for each byte and all letters are lower case.
        Parameters:
        data - byte array to be encoded
        Returns:
        object which will write the hex encoding of the byte array
        See Also:
        Integer.toHexString(int)
      • encodeHex

        public static Writable encodeHex​(byte[] data)
        Produces a Writable that writes the hex encoding of the byte[]. Calling toString() on this Writable returns the hex encoding as a String. The hex encoding includes two characters for each byte and all letters are lower case.
        Parameters:
        data - byte array to be encoded
        Returns:
        object which will write the hex encoding of the byte array
        See Also:
        Integer.toHexString(int)
      • decodeHex

        public static byte[] decodeHex​(String value)
        Decodes a hex string to a byte array. The hex string can contain either upper case or lower case letters.
        Parameters:
        value - string to be decoded
        Returns:
        decoded byte array
        Throws:
        NumberFormatException - If the string contains an odd number of characters or if the characters are not valid hexadecimal values.