Package org.apache.nutch.util
Class StringUtil
java.lang.Object
org.apache.nutch.util.StringUtil
A collection of String processing utility methods.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcleanField(String value) Simple character substitution which cleans/removes all � chars from a given String.static byte[]fromHexString(String text) Convert a String containing consecutive (no inside whitespace) hexadecimal digits into a corresponding byte array.static booleanChecks if a string is empty (ie is null or empty).static StringReturns a copy ofs(left padded) with leading spaces so that it's length islength.static voidstatic StringMask sensitive strings - passwords, etc.static StringMask sensitive strings - passwords, etc.static StringMask sensitive strings - passwords, etc.static StringReturns a copy ofs(right padded) with trailing spaces so that it's length islength.static StringtoHexString(byte[] buf) Convenience call fortoHexString(byte[], String, int), wheresep = null; lineLen = Integer.MAX_VALUE.static StringtoHexString(byte[] buf, String sep, int lineLen) Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
rightPad
Returns a copy ofs(right padded) with trailing spaces so that it's length islength. Strings alreadylengthcharacters long or longer are not altered.- Parameters:
s- input string to be copied and processedlength- desired final length of padded string- Returns:
- the resulting padded string
-
leftPad
Returns a copy ofs(left padded) with leading spaces so that it's length islength. Strings alreadylengthcharacters long or longer are not altered.- Parameters:
s- input string to be copied and processedlength- desired final length of padded string- Returns:
- the resulting padded string
-
toHexString
Convenience call fortoHexString(byte[], String, int), wheresep = null; lineLen = Integer.MAX_VALUE.- Parameters:
buf- input data for which to generate a hex string- Returns:
- the hex string
-
toHexString
Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.- Parameters:
buf- input data for which to generate a hex stringsep- separate every pair of hexadecimal digits with this separator, or null if no separation is needed.lineLen- break the output String into lines containing output for lineLen bytes.- Returns:
- the hex string
-
fromHexString
Convert a String containing consecutive (no inside whitespace) hexadecimal digits into a corresponding byte array. If the number of digits is not even, a '0' will be appended in the front of the String prior to conversion. Leading and trailing whitespace is ignored.- Parameters:
text- input text- Returns:
- converted byte array, or null if unable to convert
-
isEmpty
Checks if a string is empty (ie is null or empty).- Parameters:
str- the String to check for being empty or null- Returns:
- true if empty or null, false otherwise
-
cleanField
Simple character substitution which cleans/removes all � chars from a given String.- Parameters:
value- the String to clean- Returns:
- substituted cleaned string
-
mask
Mask sensitive strings - passwords, etc.- Parameters:
str- input string- Returns:
- the masked string, all characters replaced by
*
-
mask
Mask sensitive strings - passwords, etc.- Parameters:
str- input stringmask- char used for masking- Returns:
- the masked string, all characters replaced by the mask character
-
mask
Mask sensitive strings - passwords, etc.- Parameters:
str- input stringpattern- pattern which defines capturing groups to be masked in inputmask- char used for masking- Returns:
- the masked string, all characters matched in capturing groups of the pattern replaced by the mask character
-
main
-