Class StringUtil


  • public class StringUtil
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String Base64Digits  
      static java.lang.String UrlSafeBase64Digits  
      static java.nio.charset.Charset UTF8  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String base64Encode​(byte[] data)  
      static java.lang.String base64EncodeGeneric​(java.lang.String digits, byte[] data)  
      static java.lang.String binaryToHex​(byte[] data)  
      static java.lang.String binaryToHex​(byte[] data, int offset, int length)
      Convert a string of binary bytes to the equivalent hexadecimal string.
      static char hexDigit​(int i)  
      static java.lang.String javaQuotedLiteral​(java.lang.String value)
      Given a string, returns the representation of that string as a Java string literal.
      static java.lang.String javaQuotedLiterals​(java.lang.Iterable<java.lang.String> value)  
      static java.lang.String javaQuotedLiterals​(java.lang.String[] value)  
      static java.lang.String join​(java.util.Collection<java.lang.String> strings, java.lang.String delimiter)  
      static java.lang.String jq​(java.lang.Iterable<java.lang.String> value)
      static java.lang.String jq​(java.lang.String value)
      static java.lang.String jq​(java.lang.String[] value)
      static boolean secureStringEquals​(java.lang.String a, java.lang.String b)
      When you're comparing two strings for equality and one of them is a value that could be provided by an attacker and the other is a value that the attacker shouldn't know, use this function to check for equality.
      static byte[] stringToUtf8​(java.lang.String s)  
      static java.lang.String urlSafeBase64Encode​(byte[] data)  
      static java.lang.String utf8ToString​(byte[] utf8Data)  
      static java.lang.String utf8ToString​(byte[] utf8Data, int offset, int length)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UTF8

        public static final java.nio.charset.Charset UTF8
      • UrlSafeBase64Digits

        public static final java.lang.String UrlSafeBase64Digits
        See Also:
        Constant Field Values
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • hexDigit

        public static char hexDigit​(int i)
      • utf8ToString

        public static java.lang.String utf8ToString​(byte[] utf8Data)
                                             throws java.nio.charset.CharacterCodingException
        Throws:
        java.nio.charset.CharacterCodingException
      • utf8ToString

        public static java.lang.String utf8ToString​(byte[] utf8Data,
                                                    int offset,
                                                    int length)
                                             throws java.nio.charset.CharacterCodingException
        Throws:
        java.nio.charset.CharacterCodingException
      • stringToUtf8

        public static byte[] stringToUtf8​(java.lang.String s)
      • javaQuotedLiteral

        public static java.lang.String javaQuotedLiteral​(java.lang.String value)
        Given a string, returns the representation of that string as a Java string literal.
      • javaQuotedLiterals

        public static java.lang.String javaQuotedLiterals​(java.lang.String[] value)
      • javaQuotedLiterals

        public static java.lang.String javaQuotedLiterals​(java.lang.Iterable<java.lang.String> value)
      • binaryToHex

        public static java.lang.String binaryToHex​(byte[] data)
      • binaryToHex

        public static java.lang.String binaryToHex​(byte[] data,
                                                   int offset,
                                                   int length)
        Convert a string of binary bytes to the equivalent hexadecimal string. The resulting String will have two characters for every byte in the input.
      • secureStringEquals

        public static boolean secureStringEquals​(java.lang.String a,
                                                 java.lang.String b)
        When you're comparing two strings for equality and one of them is a value that could be provided by an attacker and the other is a value that the attacker shouldn't know, use this function to check for equality. Using regular String.equals is not secure.
      • base64Encode

        public static java.lang.String base64Encode​(byte[] data)
      • urlSafeBase64Encode

        public static java.lang.String urlSafeBase64Encode​(byte[] data)
      • base64EncodeGeneric

        public static java.lang.String base64EncodeGeneric​(java.lang.String digits,
                                                           byte[] data)
      • join

        public static java.lang.String join​(java.util.Collection<java.lang.String> strings,
                                            java.lang.String delimiter)