@InterfaceAudience.Private @InterfaceStability.Unstable public class HiveStringUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
HiveStringUtils.TraditionalBinaryPrefix
The traditional binary prefixes, kilo, mega, ..., exa,
which can be represented by a 64-bit integer.
|
Modifier and Type | Field and Description |
---|---|
static char |
COMMA |
static String |
COMMA_STR |
static String[] |
emptyStringArray |
static char |
ESCAPE_CHAR |
static int |
SHUTDOWN_HOOK_PRIORITY
Priority of the StringUtils shutdown hook.
|
Constructor and Description |
---|
HiveStringUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
arrayToString(String[] strs)
Given an array of strings, return a comma-separated list of its elements.
|
static String |
byteDesc(long len)
Return an abbreviated English-language desc of the byte length
|
static String |
byteToHexString(byte[] bytes)
Same as byteToHexString(bytes, 0, bytes.length).
|
static String |
byteToHexString(byte[] bytes,
int start,
int end)
Given an array of bytes it will convert the bytes to a hex string
representation of the bytes
|
static String |
camelize(String s)
Convert SOME_STUFF to SomeStuff
|
static boolean |
commentProvided(char[] chars) |
static String |
escapeHTML(String string)
Escapes HTML Special characters present in the string.
|
static String |
escapeString(String str)
Escape commas in the string using the default escape char
|
static String |
escapeString(String str,
char escapeChar,
char charToEscape)
Escape
charToEscape in the string
with the escape char escapeChar |
static String |
escapeString(String str,
char escapeChar,
char[] charsToEscape) |
static int |
findNext(String str,
char separator,
char escapeChar,
int start,
StringBuilder split)
Finds the first occurrence of the separator character ignoring the escaped
separators starting from the index.
|
static String |
formatPercent(double done,
int digits)
Format a percentage for presentation to the user.
|
static String |
formatTime(long timeDiff)
Given the time in long milliseconds, returns a
String in the format Xhrs, Ymins, Z sec.
|
static String |
formatTimeDiff(long finishTime,
long startTime)
Given a finish and start time in long milliseconds, returns a
String in the format Xhrs, Ymins, Z sec, for the time difference between two times.
|
static String |
getFormattedTimeWithDiff(DateFormat dateFormat,
long finishTime,
long startTime)
Formats time in ms and appends difference (finishTime - startTime)
as returned by formatTimeDiff().
|
static String |
getHostname()
Return hostname without throwing exception.
|
static Map |
getPropertiesExplain(Properties properties) |
static Collection<String> |
getStringCollection(String str)
Returns a collection of strings.
|
static String[] |
getStrings(String str)
Returns an arraylist of strings.
|
static int |
getTextUtfLength(org.apache.hadoop.io.Text t) |
static Collection<String> |
getTrimmedStringCollection(String str)
Splits a comma separated value
String , trimming leading and trailing whitespace on each value. |
static String[] |
getTrimmedStrings(String str)
Splits a comma separated value
String , trimming leading and trailing whitespace on each value. |
static byte[] |
hexStringToByte(String hex)
Given a hexstring this will return the byte array corresponding to the
string
|
static String |
humanReadableInt(long number)
Given an integer, return a string that is in an approximate, but human
readable format.
|
static List<String> |
intern(List<String> list)
Return an interned list with identical contents as the given list.
|
static Map<String,String> |
intern(Map<String,String> map)
Return an interned map with identical contents as the given map.
|
static String |
intern(String str)
Return the internalized string, or null if the given string is null.
|
static boolean |
isUtfStartByte(byte b)
Checks if b is the first byte of a UTF-8 character.
|
static String |
join(CharSequence separator,
Iterable<?> strings)
Concatenates strings, using a separator.
|
static String |
limitDecimalTo2(double d) |
static String |
normalizeIdentifier(String identifier) |
static String |
quoteComments(String value) |
static String |
simpleHostname(String fullHostname)
Given a full hostname, return the word upto the first dot.
|
static String[] |
split(String str)
Split a string using the default separator
|
static String[] |
split(String str,
char separator)
Split a string using the given separator, with no escaping performed.
|
static String[] |
split(String str,
char escapeChar,
char separator)
Split a string using the given separator
|
static String[] |
splitAndUnEscape(String str)
Split a string using the default separator/escape character,
then unescape the resulting array of strings
|
static String[] |
splitAndUnEscape(String str,
char escapeChar,
char separator)
Split a string using the specified separator/escape character,
then unescape the resulting array of strings using the same escape/separator.
|
static void |
startupShutdownMessage(Class<?> clazz,
String[] args,
org.apache.commons.logging.Log LOG)
Print a log message for starting up and shutting down
|
static String |
stringifyException(Throwable e)
Make a string representation of the exception.
|
static org.apache.hadoop.fs.Path[] |
stringToPath(String[] str) |
static URI[] |
stringToURI(String[] str) |
static String |
unEscapeString(String str)
Unescape commas in the string using the default escape char
|
static String |
unEscapeString(String str,
char escapeChar,
char charToEscape)
Unescape
charToEscape in the string
with the escape char escapeChar |
static String |
unEscapeString(String str,
char escapeChar,
char[] charsToEscape) |
static String |
uriToString(URI[] uris) |
public static final int SHUTDOWN_HOOK_PRIORITY
public static final String[] emptyStringArray
public static final char COMMA
public static final String COMMA_STR
public static final char ESCAPE_CHAR
public static String intern(String str)
str
- The string to internpublic static List<String> intern(List<String> list)
list
- The list whose strings will be internedpublic static Map<String,String> intern(Map<String,String> map)
map
- The map whose strings will be internedpublic static String stringifyException(Throwable e)
e
- The exception to stringifypublic static String simpleHostname(String fullHostname)
fullHostname
- the full hostnamepublic static String humanReadableInt(long number)
number
- the number to formatpublic static String formatPercent(double done, int digits)
done
- the percentage to format (0.0 to 1.0)digits
- the number of digits past the decimal pointpublic static String arrayToString(String[] strs)
strs
- Array of stringspublic static String byteToHexString(byte[] bytes, int start, int end)
bytes
- start
- start index, inclusivelyend
- end index, exclusivelypublic static String byteToHexString(byte[] bytes)
public static byte[] hexStringToByte(String hex)
hex
- the hex String arraypublic static URI[] stringToURI(String[] str)
str
- The string array to be parsed into an URI array.IllegalArgumentException
- If any string in str violates RFC 2396.public static org.apache.hadoop.fs.Path[] stringToPath(String[] str)
str
- public static String formatTimeDiff(long finishTime, long startTime)
finishTime
- finish timestartTime
- start timepublic static String formatTime(long timeDiff)
timeDiff
- The time difference to formatpublic static String getFormattedTimeWithDiff(DateFormat dateFormat, long finishTime, long startTime)
dateFormat
- date format to usefinishTime
- fnish timestartTime
- start timepublic static String[] getStrings(String str)
str
- the comma seperated string valuespublic static Collection<String> getStringCollection(String str)
str
- comma seperated string valuesArrayList
of string valuespublic static Collection<String> getTrimmedStringCollection(String str)
String
, trimming leading and trailing whitespace on each value.str
- a comma separated Collection
of String
valuespublic static String[] getTrimmedStrings(String str)
String
, trimming leading and trailing whitespace on each value.str
- a comma separated String
valuespublic static String[] split(String str)
str
- a string that may have escaped separatorpublic static String[] split(String str, char escapeChar, char separator)
str
- a string that may have escaped separatorescapeChar
- a char that be used to escape the separatorseparator
- a separator charpublic static String[] split(String str, char separator)
str
- a string to be split. Note that this may not be null.separator
- a separator charpublic static String[] splitAndUnEscape(String str)
str
- public static String[] splitAndUnEscape(String str, char escapeChar, char separator)
str
- a string that may have escaped separatorescapeChar
- a char that be used to escape the separatorseparator
- a separator charpublic static int findNext(String str, char separator, char escapeChar, int start, StringBuilder split)
str
- the source stringseparator
- the character to findescapeChar
- character used to escapestart
- from where to searchsplit
- used to pass back the extracted stringpublic static String escapeString(String str)
str
- a stringpublic static String escapeString(String str, char escapeChar, char charToEscape)
charToEscape
in the string
with the escape char escapeChar
str
- stringescapeChar
- escape charcharToEscape
- the char to be escapedpublic static String escapeString(String str, char escapeChar, char[] charsToEscape)
charsToEscape
- array of characters to be escapedpublic static String unEscapeString(String str)
str
- a stringpublic static String unEscapeString(String str, char escapeChar, char charToEscape)
charToEscape
in the string
with the escape char escapeChar
str
- stringescapeChar
- escape charcharToEscape
- the escaped charpublic static String unEscapeString(String str, char escapeChar, char[] charsToEscape)
charsToEscape
- array of characters to unescapepublic static void startupShutdownMessage(Class<?> clazz, String[] args, org.apache.commons.logging.Log LOG)
clazz
- the class of the serverargs
- argumentsLOG
- the target log objectpublic static String getHostname()
public static String escapeHTML(String string)
string
- public static String byteDesc(long len)
public static String limitDecimalTo2(double d)
public static String join(CharSequence separator, Iterable<?> strings)
separator
- Separator to join with.strings
- Strings to join.public static String camelize(String s)
s
- input stringpublic static boolean isUtfStartByte(byte b)
public static int getTextUtfLength(org.apache.hadoop.io.Text t)
public static Map getPropertiesExplain(Properties properties)
public static boolean commentProvided(char[] chars)
Copyright © 2017 The Apache Software Foundation. All rights reserved.