Package org.codehaus.groovy.runtime
Class EncodingGroovyMethods
- java.lang.Object
- 
- org.codehaus.groovy.runtime.EncodingGroovyMethods
 
- 
 public class EncodingGroovyMethods extends java.lang.ObjectThis 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 SummaryConstructors Constructor Description EncodingGroovyMethods()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decodeBase64(java.lang.String value)Decode the String from Base64 into a byte array.static byte[]decodeBase64Url(java.lang.String value)Decodes a Base64 URL and Filename Safe encoded String into a byte array.static byte[]decodeHex(java.lang.String value)Decodes a hex string to a byte array.static java.lang.Stringdigest(byte[] self, java.lang.String algorithm)digest the byte arraystatic java.lang.Stringdigest(java.lang.CharSequence self, java.lang.String algorithm)digest the CharSequence instancestatic WritableencodeBase64(byte[] data)Produce a Writable object which writes the Base64 encoding of the byte array.static WritableencodeBase64(byte[] data, boolean chunked)Produce a Writable object which writes the Base64 encoding of the byte array.static WritableencodeBase64(java.lang.Byte[] data)Produce a Writable object which writes the Base64 encoding of the byte array.static WritableencodeBase64(java.lang.Byte[] data, boolean chunked)Produce a Writable object which writes the Base64 encoding of the byte array.static WritableencodeBase64Url(byte[] data)Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array.static WritableencodeBase64Url(byte[] data, boolean pad)Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array.static WritableencodeBase64Url(java.lang.Byte[] data)Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array.static WritableencodeBase64Url(java.lang.Byte[] data, boolean pad)Produce a Writable object which writes the Base64 URL and Filename Safe encoding of the byte array.static WritableencodeHex(byte[] data)Produces a Writable that writes the hex encoding of the byte[].static WritableencodeHex(java.lang.Byte[] data)Produces a Writable that writes the hex encoding of the Byte[].static java.lang.Stringmd5(byte[] self)Calculate md5 of the byte arraystatic java.lang.Stringmd5(java.lang.CharSequence self)Calculate md5 of the CharSequence instancestatic java.lang.Stringsha256(byte[] self)Calculate SHA-256 of the byte arraystatic java.lang.Stringsha256(java.lang.CharSequence self)Calculate SHA-256 of the CharSequence instance
 
- 
- 
- 
Method Detail- 
encodeBase64public static Writable encodeBase64(java.lang.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 seeRFC 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
 
 - 
encodeBase64public static Writable encodeBase64(java.lang.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 seeRFC 4648.- Parameters:
- data- Byte array to be encoded
- Returns:
- object which will write the Base64 encoding of the byte array
- Since:
- 1.0
 
 - 
encodeBase64public 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 seeRFC 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
 
 - 
encodeBase64public 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 seeRFC 4648.- Parameters:
- data- byte array to be encoded
- Returns:
- object which will write the Base64 encoding of the byte array
- Since:
- 1.0
 
 - 
encodeBase64Urlpublic static Writable encodeBase64Url(java.lang.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 seeRFC 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 offalse.- 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)
 
 - 
encodeBase64Urlpublic static Writable encodeBase64Url(java.lang.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 seeRFC 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
 
 - 
encodeBase64Urlpublic 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 seeRFC 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 offalse.- 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)
 
 - 
encodeBase64Urlpublic 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 seeRFC 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
 
 - 
decodeBase64public static byte[] decodeBase64(java.lang.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
 
 - 
decodeBase64Urlpublic static byte[] decodeBase64Url(java.lang.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
 
 - 
encodeHexpublic static Writable encodeHex(java.lang.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)
 
 - 
encodeHexpublic 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)
 
 - 
decodeHexpublic static byte[] decodeHex(java.lang.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:
- java.lang.NumberFormatException- If the string contains an odd number of characters or if the characters are not valid hexadecimal values.
 
 - 
md5public static java.lang.String md5(java.lang.CharSequence self) throws java.security.NoSuchAlgorithmExceptionCalculate md5 of the CharSequence instance- Returns:
- md5 value
- Throws:
- java.security.NoSuchAlgorithmException- if MD5 algorithm not found
- Since:
- 2.5.0
 
 - 
md5public static java.lang.String md5(byte[] self) throws java.security.NoSuchAlgorithmExceptionCalculate md5 of the byte array- Returns:
- md5 value
- Throws:
- java.security.NoSuchAlgorithmException- if MD5 algorithm not found
- Since:
- 2.5.0
 
 - 
sha256public static java.lang.String sha256(java.lang.CharSequence self) throws java.security.NoSuchAlgorithmExceptionCalculate SHA-256 of the CharSequence instance- Returns:
- SHA-256 value
- Throws:
- java.security.NoSuchAlgorithmException- if SHA-256 algorithm not found
- Since:
- 2.5.3
 
 - 
sha256public static java.lang.String sha256(byte[] self) throws java.security.NoSuchAlgorithmExceptionCalculate SHA-256 of the byte array- Returns:
- SHA-256 value
- Throws:
- java.security.NoSuchAlgorithmException- if SHA-256 algorithm not found
- Since:
- 2.5.3
 
 - 
digestpublic static java.lang.String digest(java.lang.CharSequence self, java.lang.String algorithm) throws java.security.NoSuchAlgorithmExceptiondigest the CharSequence instance- Parameters:
- algorithm- the name of the algorithm requested, e.g. MD5, SHA-1, SHA-256, etc.
- Returns:
- digested value
- Throws:
- java.security.NoSuchAlgorithmException- if the algorithm not found
- Since:
- 2.5.0
- See Also:
- MessageDigest.getInstance(java.lang.String)
 
 - 
digestpublic static java.lang.String digest(byte[] self, java.lang.String algorithm) throws java.security.NoSuchAlgorithmExceptiondigest the byte array- Parameters:
- algorithm- the name of the algorithm requested, e.g. MD5, SHA-1, SHA-256, etc.
- Returns:
- digested value
- Throws:
- java.security.NoSuchAlgorithmException- if the algorithm not found
- Since:
- 2.5.0
- See Also:
- MessageDigest.getInstance(java.lang.String)
 
 
- 
 
-