Documentation of 'org.clapper.util.text.TextUtil' Java class
TextUtil
org.clapper.util.text

Class TextUtil



  • public final class TextUtil
    extends java.lang.Object
    Static class containing miscellaneous text utility methods.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static char[] HEXADECIMAL_DIGITS
      Set of digits suitable for encoding a number as a hexadecimal string.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static boolean booleanFromString(java.lang.String s)
      Convert a boolean string to a boolean value.
      static byte[] bytesForHexadecimal(java.lang.String hexString)
      Takes a string of hexadecimal-encoded byte values and converts it back to an array of bytes.
      static java.lang.String centerString(java.lang.String s, int width)
      Center a string in a fixed-width field, using blanks for padding.
      static java.lang.String centerString(java.lang.String s, int width, char c)
      Center a string in a fixed-width field, using the specified character for padding.
      static java.lang.String charToUnicodeEscape(char c)
      Convert a character to its corresponding Unicode escape sequence.
      static java.lang.String charToUnicodeEscape(char c, java.lang.StringBuilder buf)
      Convert a character to its corresponding Unicode escape sequence.
      static java.lang.StringBuilder encodeNumber(int num, int base, char[] digits, java.lang.StringBuilder buf)
      Encode an integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding.
      static java.lang.StringBuilder encodeNumber(long num, int base, char[] digits, java.lang.StringBuilder buf)
      Encode a long integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding.
      static java.lang.StringBuilder encodeNumber(short num, int base, char[] digits, java.lang.StringBuilder buf)
      Encode a short integer in an arbitrary base; the caller specifies an array of digit characters to be used for the encoding.
      static java.lang.StringBuilder hexadecimalForByte(byte b, java.lang.StringBuilder buf)
      Encode a byte as a two-digit hexadecimal string, appending the result to a StringBuilder.
      static java.lang.StringBuilder hexadecimalForByte(int b, java.lang.StringBuilder buf)
      Encode a byte as a two-digit hexadecimal string, appending the result to a StringBuilder.The hexadecimal string uses lower-case digits.
      static java.lang.String hexadecimalForBytes(byte[] bytes)
      Encode an array of bytes as a hexadecimal string, returning the string.
      static java.lang.StringBuilder hexadecimalForBytes(byte[] bytes, int start, int end, java.lang.StringBuilder buf)
      Encode an array of bytes as a hexadecimal string, appending the result to a StringBuilder.
      static java.lang.StringBuilder hexadecimalForBytes(int[] bytes, int start, int end, java.lang.StringBuilder buf)
      Encode an array of bytes as a hexadecimal string, appending the result to a StringBuilder.
      static java.lang.String hexadecimalForNumber(int num)
      Encode an integer as a hexadecimal string, returning the hex string.
      static java.lang.StringBuilder hexadecimalForNumber(int num, java.lang.StringBuilder buf)
      Encode an integer as a hexadecimal string, appending the result to a StringBuilder.
      static java.lang.String hexadecimalForNumber(long num)
      Encode a long as a hexadecimal string, returning the hex string.
      static java.lang.StringBuilder hexadecimalForNumber(long num, java.lang.StringBuilder buf)
      Encode a long as a hexadecimal string, appending the result to a StringBuilder.
      static java.lang.String hexadecimalForNumber(short num)
      Encode a short as a hexadecimal string, returning the hex string.
      static java.lang.StringBuilder hexadecimalForNumber(short num, java.lang.StringBuilder buf)
      Encode a short as a hexadecimal string, appending the result to a StringBuilder.
      static boolean isPrintable(char c)
      Determine whether a character is printable.
      static java.lang.String join(char delim, java.lang.String... strings)
      Join a set of strings into one string, putting the specified delimiter between adjacent strings.
      static java.lang.String join(java.util.Collection<? extends java.lang.Object> objects, char delim)
      Join a set of strings into one string, putting the specified delimiter between adjacent strings.
      static java.lang.String join(java.util.Collection<? extends java.lang.Object> objects, java.lang.String delim)
      Join a set of strings into one string, putting the specified delimiter between adjacent strings.
      static java.lang.String join(java.lang.String[] strings, char delim)
      Join an array of strings into one string, putting the specified delimiter between adjacent strings.
      static java.lang.String join(java.lang.String[] strings, int start, int end, char delim)
      Join an array of strings into one string, putting the specified delimiter between adjacent strings, starting at a specified index.
      static java.lang.String join(java.lang.String[] strings, int start, int end, java.lang.String delim)
      Join an array of strings into one string, putting the specified delimiter between adjacent strings, starting at a specified index.
      static java.lang.String join(java.lang.String[] strings, java.lang.String delim)
      Join a set of strings into one string, putting the specified delimiter between adjacent strings.
      static java.lang.String join(java.lang.String delim, java.lang.String... strings)
      Join a set of strings into one string, putting the specified delimiter between adjacent strings.
      static java.lang.String leftJustifyString(java.lang.String s, int width)
      Left justify a string in a fixed-width field, using blanks for padding.
      static java.lang.String leftJustifyString(java.lang.String s, int width, char c)
      Left justify a string in a fixed-width field, using the specified character for padding.
      static java.lang.String rightJustifyString(java.lang.String s, int width)
      Right justify a string in a fixed-width field, using blanks for padding.
      static java.lang.String rightJustifyString(java.lang.String s, int width, char c)
      Right justify a string in a fixed-width field, using the specified character for padding.
      static java.lang.String romanNumeralsForNumber(int n)
      Get the (upper-case) Roman numeral string for a number.
      static java.lang.String[] split(java.lang.String s)
      Split a string on white space, into one or more strings.
      static java.lang.String[] split(java.lang.String s, boolean preserveEmptyFields)
      Split a string on white space, into one or more strings.
      static java.lang.String[] split(java.lang.String s, char delim)
      Split a string into one or more strings, based on a delimiter.
      static java.lang.String[] split(java.lang.String s, char delim, boolean preserveEmptyFields)
      Split a string into one or more strings, based on a delimiter.
      static int split(java.lang.String s, char delim, java.util.Collection<java.lang.String> collection)
      Split a string into one or more strings, based on a delimiter.
      static int split(java.lang.String s, char delim, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)
      Split a string into one or more strings, based on a delimiter.
      static int split(java.lang.String s, java.util.Collection<java.lang.String> collection)
      Split a string on white space, into one or more strings.
      static int split(java.lang.String s, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)
      Split a string on white space, into one or more strings.
      static java.lang.String[] split(java.lang.String s, java.lang.String delimSet)
      Split a string into one or more strings, based on a set of delimiter.
      static java.lang.String[] split(java.lang.String s, java.lang.String delimSet, boolean preserveEmptyFields)
      Split a string into one or more strings, based on a set of delimiter.
      static int split(java.lang.String s, java.lang.String delimSet, java.util.Collection<java.lang.String> collection)
      Split a string into one or more strings, based on a set of delimiter.
      static int split(java.lang.String s, java.lang.String delimSet, java.util.Collection<java.lang.String> collection, boolean preserveEmptyFields)
      Split a string into one or more strings, based on a set of delimiter.
      static boolean stringIsEmpty(java.lang.String s)
      Determine whether a given string is empty.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • booleanFromString

        public static boolean booleanFromString(java.lang.String s)
                                         throws java.lang.IllegalArgumentException
        Convert a boolean string to a boolean value. This method is more generous than java.lang.Boolean.booleanValue(). The following strings (in upper or lower case) are recognized as true: "1", "true", "yes", "y". The following strings (in upper or lower case) are recognized as false: "0", "false", "no", "n".
        Parameters:
        s - string to convert
        Returns:
        true or false
        Throws:
        java.lang.IllegalArgumentException - string isn't a boolean
      • split

        public static java.lang.String[] split(java.lang.String s)

        Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the split(String,boolean) method.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        Returns:
        an array of String objects
        See Also:
        split(String,boolean), split(String,String), split(String,char), split(String,Collection), split(String,char,Collection), split(String,String,Collection)
      • split

        public static java.lang.String[] split(java.lang.String s,
                                               boolean preserveEmptyFields)

        Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        preserveEmptyFields - Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)
        Returns:
        an array of String objects
        See Also:
        split(String), split(String,String), split(String,char), split(String,Collection), split(String,char,Collection), split(String,String,Collection)
      • split

        public static int split(java.lang.String s,
                                java.util.Collection<java.lang.String> collection)

        Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the split(String,Collection,boolean) method.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        collection - where to store the split strings
        Returns:
        the number of strings added to the collection
        See Also:
        split(String,Collection,boolean), split(String), split(String,String), split(String,char), split(String,char,Collection), split(String,String,Collection)
      • split

        public static int split(java.lang.String s,
                                java.util.Collection<java.lang.String> collection,
                                boolean preserveEmptyFields)

        Split a string on white space, into one or more strings. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        collection - where to store the split strings
        preserveEmptyFields - Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)
        Returns:
        the number of strings added to the collection
        See Also:
        split(String,Collection), split(String), split(String,String), split(String,char), split(String,char,Collection), split(String,String,Collection)
      • split

        public static java.lang.String[] split(java.lang.String s,
                                               char delim)

        Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the split(String,char,boolean) method.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        delim - the delimiter
        Returns:
        an array of String objects
        See Also:
        split(String,char,boolean), split(String), split(String,String), split(String,Collection), split(String,char,Collection), split(String,String,Collection)
      • split

        public static java.lang.String[] split(java.lang.String s,
                                               char delim,
                                               boolean preserveEmptyFields)

        Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        delim - the delimiter
        preserveEmptyFields - Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)
        Returns:
        an array of String objects
        See Also:
        split(String,char), split(String), split(String,String), split(String,Collection), split(String,char,Collection), split(String,String,Collection)
      • split

        public static java.lang.String[] split(java.lang.String s,
                                               java.lang.String delimSet)

        Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the split(String,String,boolean) method.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        delimSet - set of delimiters, or null to use white space
        Returns:
        an array of String objects
        See Also:
        split(String,String,boolean), split(String), split(String,char), split(String,Collection), split(String,char,Collection), split(String,String,Collection)
      • split

        public static java.lang.String[] split(java.lang.String s,
                                               java.lang.String delimSet,
                                               boolean preserveEmptyFields)

        Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        delimSet - set of delimiters, or null to use white space
        preserveEmptyFields - Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)
        Returns:
        an array of String objects
        See Also:
        split(String,String), split(String), split(String,char), split(String,Collection), split(String,char,Collection), split(String,String,Collection)
      • split

        public static int split(java.lang.String s,
                                char delim,
                                java.util.Collection<java.lang.String> collection)

        Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the split(String,char,Collection,boolean) method.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        delim - the delimiter
        collection - where to store the split strings
        Returns:
        the number of String objects added to the collection
        See Also:
        split(String,char,Collection,boolean), split(String), split(String,char), split(String,Collection), split(String,String), split(String,String,Collection)
      • split

        public static int split(java.lang.String s,
                                char delim,
                                java.util.Collection<java.lang.String> collection,
                                boolean preserveEmptyFields)

        Split a string into one or more strings, based on a delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        Parameters:
        s - the string to split
        delim - the delimiter
        collection - where to store the split strings
        preserveEmptyFields - Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)
        Returns:
        the number of String objects added to the collection
        See Also:
        split(String,char,Collection), split(String), split(String,char), split(String,Collection), split(String,String), split(String,String,Collection)
      • split

        public static int split(java.lang.String s,
                                java.lang.String delimSet,
                                java.util.Collection<java.lang.String> collection)

        Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the split(String,String,Collection,boolean) method.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the split(String,String,Collection,boolean) method.

        Parameters:
        s - the string to split
        delimSet - set of delimiters
        collection - where to store the split strings
        Returns:
        the number of String objects added to the collection
        See Also:
        split(String,String,Collection,boolean), split(String), split(String,char), split(String,Collection), split(String,String), split(String,char,Collection)
      • split

        public static int split(java.lang.String s,
                                java.lang.String delimSet,
                                java.util.Collection<java.lang.String> collection,
                                boolean preserveEmptyFields)

        Split a string into one or more strings, based on a set of delimiter. This method is intended to be reminiscent of the corresponding perl or awk split() function, though without regular expression support. This method uses a StringTokenizer to do the actual work.

        Note that the 1.4 JDK introduces a regular expression-based split() method in the java.lang.String class. This method does not use regular expressions.

        This version of split() does not preserve empty strings. That is, the string "a:b::c", when split with a ":" delimiter, yields three fields ("a", "b", "c"), since the two adjacent ":" characters are treated as one delimiter. To preserve empty strings, pass true as the preserveEmptyFields parameter to the split(String,String,Collection,boolean) method.

        Parameters:
        s - the string to split
        delimSet - set of delimiters
        collection - where to store the split strings
        preserveEmptyFields - Whether to parse through empty tokens or preserve them. For example, given the string string "a:b::c" and a delimiter of ":", if preserveEmptyStrings is true, then this method will return four strings, "a", "b", "", "c". If preserveEmptyStrings is false, then this method will return three strings, "a", "b", "c" (since the two adjacent ":" characters are treated as one delimiter.)
        Returns:
        the number of String objects added to the collection
        See Also:
        split(String,String,Collection), split(String), split(String,char), split(String,Collection), split(String,String), split(String,char,Collection)
      • join

        public static java.lang.String join(java.lang.String[] strings,
                                            java.lang.String delim)
        Join a set of strings into one string, putting the specified delimiter between adjacent strings.
        Parameters:
        strings - the strings to be joined
        delim - the delimiter string
        Returns:
        the joined string, or "" if the array is empty.
        See Also:
        split(String,String), join(String[],char)
      • join

        public static java.lang.String join(java.lang.String delim,
                                            java.lang.String... strings)
        Join a set of strings into one string, putting the specified delimiter between adjacent strings. This version of join() supports the new Java variable argument syntax.
        Parameters:
        delim - the delimiter string
        strings - the strings to be joined
        Returns:
        the joined string, or "" if the array is empty.
        See Also:
        split(String,char), join(String[],String)
      • join

        public static java.lang.String join(java.lang.String[] strings,
                                            char delim)
        Join an array of strings into one string, putting the specified delimiter between adjacent strings.
        Parameters:
        strings - the strings to be joined
        delim - the delimiter character
        Returns:
        the joined string, or "" if the array is empty.
        See Also:
        split(String,char), join(String[],String)
      • join

        public static java.lang.String join(java.lang.String[] strings,
                                            int start,
                                            int end,
                                            char delim)
        Join an array of strings into one string, putting the specified delimiter between adjacent strings, starting at a specified index.
        Parameters:
        strings - the strings to be joined
        start - starting index
        end - one past the ending index
        delim - the delimiter character
        Returns:
        the joined string, or "" if the array is empty.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - bad value for start or end
        See Also:
        split(String,char), join(String[],String)
      • join

        public static java.lang.String join(java.lang.String[] strings,
                                            int start,
                                            int end,
                                            java.lang.String delim)
        Join an array of strings into one string, putting the specified delimiter between adjacent strings, starting at a specified index.
        Parameters:
        strings - the strings to be joined
        start - starting index
        end - one past the ending index
        delim - the delimiter string
        Returns:
        the joined string, or "" if the array is empty.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - bad value for start or end
        See Also:
        split(String,char), join(String[],String)
      • join

        public static java.lang.String join(char delim,
                                            java.lang.String... strings)
        Join a set of strings into one string, putting the specified delimiter between adjacent strings. This version of join() supports the new Java variable argument syntax.
        Parameters:
        delim - the delimiter character
        strings - the strings to be joined
        Returns:
        the joined string, or "" if the array is empty.
        See Also:
        split(String,char), join(String[],String)
      • join

        public static java.lang.String join(java.util.Collection<? extends java.lang.Object> objects,
                                            java.lang.String delim)
        Join a set of strings into one string, putting the specified delimiter between adjacent strings.
        Parameters:
        objects - A collection the items to be joined. This collection can contain objects of any type; each object's toString() method is called to produce the string to be joined.
        delim - the delimiter string
        Returns:
        the joined string, or "" if the collection is empty.
        See Also:
        split(String,String,Collection), join(Collection,char)
      • join

        public static java.lang.String join(java.util.Collection<? extends java.lang.Object> objects,
                                            char delim)
        Join a set of strings into one string, putting the specified delimiter between adjacent strings.
        Parameters:
        objects - A collection the items to be joined. This collection can contain objects of any type; each object's toString() method is called to produce the string to be joined.
        delim - the delimiter character
        Returns:
        the joined string, or "" if the collection is empty.
        See Also:
        split(String,char,Collection), join(Collection,String)
      • stringIsEmpty

        public static boolean stringIsEmpty(java.lang.String s)
        Determine whether a given string is empty. A string is empty if it is null, zero-length, or comprised entirely of white space. This method is more efficient than calling s.trim().length(), because it does not create a new string just to test its length.
        Parameters:
        s - the string to test
        Returns:
        true if it's empty, false if not.
      • rightJustifyString

        public static java.lang.String rightJustifyString(java.lang.String s,
                                                          int width)
        Right justify a string in a fixed-width field, using blanks for padding. If the string is already longer than the field width, it is returned unchanged.
        Parameters:
        s - the string
        width - the desired field width
        Returns:
        a right-justified version of the string
        See Also:
        rightJustifyString(String,int,char), leftJustifyString(String,int), centerString(String,int)
      • rightJustifyString

        public static java.lang.String rightJustifyString(java.lang.String s,
                                                          int width,
                                                          char c)
        Right justify a string in a fixed-width field, using the specified character for padding. If the string is already longer than the field width, it is returned unchanged.
        Parameters:
        s - the string
        width - the desired field width
        c - the pad character
        Returns:
        a right-justified version of the string
        See Also:
        rightJustifyString(String,int), leftJustifyString(String,int,char), centerString(String,int,char)
      • leftJustifyString

        public static java.lang.String leftJustifyString(java.lang.String s,
                                                         int width)
        Left justify a string in a fixed-width field, using blanks for padding. If the string is already longer than the field width, it is returned unchanged.
        Parameters:
        s - the string
        width - the desired field width
        Returns:
        a left-justified version of the string
        See Also:
        leftJustifyString(String,int,char), rightJustifyString(String,int), centerString(String,int)
      • leftJustifyString

        public static java.lang.String leftJustifyString(java.lang.String s,
                                                         int width,
                                                         char c)
        Left justify a string in a fixed-width field, using the specified character for padding. If the string is already longer than the field width, it is returned unchanged.
        Parameters:
        s - the string
        width - the desired field width
        c - the pad character
        Returns:
        a left-justified version of the string
        See Also:
        leftJustifyString(String,int), rightJustifyString(String,int,char), centerString(String,int,char)
      • centerString

        public static java.lang.String centerString(java.lang.String s,
                                                    int width)
        Center a string in a fixed-width field, using blanks for padding. If the string is already longer than the field width, it is returned unchanged.
        Parameters:
        s - the string
        width - the desired field width
        Returns:
        a centered version of the string
        See Also:
        centerString(String,int,char), rightJustifyString(String,int), leftJustifyString(String,int)
      • centerString

        public static java.lang.String centerString(java.lang.String s,
                                                    int width,
                                                    char c)
        Center a string in a fixed-width field, using the specified character for padding. If the string is already longer than the field width, it is returned unchanged.
        Parameters:
        s - the string
        width - the desired field width
        c - the pad character
        Returns:
        a right-justified version of the string
        See Also:
        centerString(String,int,char), leftJustifyString(String,int,char), rightJustifyString(String,int,char)
      • hexadecimalForBytes

        public static java.lang.StringBuilder hexadecimalForBytes(byte[] bytes,
                                                                  int start,
                                                                  int end,
                                                                  java.lang.StringBuilder buf)
        Encode an array of bytes as a hexadecimal string, appending the result to a StringBuilder. Note that the byte type in Java is signed. Use the other version of hexadecimalForBytes(int[],int,int,StringBuilder) if you want to pass signed byte values.
        Parameters:
        bytes - The array of bytes
        start - starting index in byte array
        end - one past ending index in byte array (thus, bytes.length is a valid value)
        buf - Where to append the result
        Returns:
        a reference to the StringBuilder, for convenience
        See Also:
        hexadecimalForByte(byte,StringBuilder), hexadecimalForByte(int,StringBuilder), bytesForHexadecimal(String)
      • hexadecimalForBytes

        public static java.lang.String hexadecimalForBytes(byte[] bytes)
        Encode an array of bytes as a hexadecimal string, returning the string. Calling this method is equivalent to:
         hexadecimalForBytes(buf, 0, buf.length, new StringBuilder()).toString()
         
        Parameters:
        bytes - The array of bytes
        Returns:
        a reference to the StringBuilder, for convenience
        See Also:
        hexadecimalForBytes(byte[],int,int,StringBuilder)
      • bytesForHexadecimal

        public static byte[] bytesForHexadecimal(java.lang.String hexString)
                                          throws java.lang.NumberFormatException

        Takes a string of hexadecimal-encoded byte values and converts it back to an array of bytes. The string may or may not contain white space; all white space is stripped before parsing begins. However, white space cannot occur between the digits for a byte; it must only occur between bytes. That is, "6f a1" is legal, while "6 f a 1" is not. Each byte must be encoded as a 2-digits hexadecimal value; as a consequence, the input string must have an even number of characters, once all white space has been stripped. The hexadecimal digits "a" through "f" may be in upper- or lower-case. An illegal hexadecimal string will result in a NumberFormatException. The following strings are examples of legal input to this method:

         1F
         66756c6c74696c742e636f6d
         42 72 69 61 6e 20 43 6c  61 70 70 65 72
         49 2D41 63 63656C
         

        The following strings are examples of illegal input:

         1X
         6
         6f a 1
         6675-6c6c-7469-6c742e-636f6d
         
        Parameters:
        hexString - the hex string to convert
        Returns:
        an array of bytes representing the decoded hex string
        Throws:
        java.lang.NumberFormatException - if the hex string is invalid
        See Also:
        hexadecimalForByte(byte,StringBuilder), hexadecimalForByte(int,StringBuilder), hexadecimalForBytes(byte[],int,int,StringBuilder), hexadecimalForBytes(int[],int,int,StringBuilder)
      • romanNumeralsForNumber

        public static java.lang.String romanNumeralsForNumber(int n)
        Get the (upper-case) Roman numeral string for a number.
        Parameters:
        n - the number; must be positive
        Returns:
        the roman number string
      • charToUnicodeEscape

        public static java.lang.String charToUnicodeEscape(char c,
                                                           java.lang.StringBuilder buf)
        Convert a character to its corresponding Unicode escape sequence.
        Parameters:
        c - the character
        buf - where to store the result
        Returns:
        the contents of buf, as a string
        See Also:
        charToUnicodeEscape(char)
      • charToUnicodeEscape

        public static java.lang.String charToUnicodeEscape(char c)
        Convert a character to its corresponding Unicode escape sequence.
        Parameters:
        c - the character
        See Also:
        charToUnicodeEscape(char)
      • isPrintable

        public static boolean isPrintable(char c)
        Determine whether a character is printable. This method uses a simple definition of "printable" that doesn't take into account specific locales. A character is assumed to be printable if (a) it's in the Basic Latin, Latin 1 Supplement, or Extended Latin A Unicode block, and (b) its type, as returned by java.lang.Character.getType() is one of:

        • Character.OTHER_PUNCTUATION
        • Character.START_PUNCTUATION
        • Character.END_PUNCTUATION
        • Character.CONNECTOR_PUNCTUATION
        • Character.CURRENCY_SYMBOL
        • Character.MATH_SYMBOL
        • Character.MODIFIER_SYMBOL
        • Character.UPPERCASE_LETTER
        • Character.LOWERCASE_LETTER
        • Character.DECIMAL_DIGIT_NUMBER
        • Character.SPACE_SEPARATOR
        • Character.DASH_PUNCTUATION

        All other characters are assumed to be non-printable, even if they could actually be printed in the current locale or on some printer.

        Parameters:
        c - the character to test
        Returns:
        whether or not it is non-

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.