@PublicEvolving public final class StringUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
arrayAwareToString(Object o)
This method calls
Object.toString() on the given object, unless the
object is an array. |
static String |
arrayToString(Object array)
Returns a string representation of the given array.
|
static String |
byteToHexString(byte[] bytes)
Given an array of bytes it will convert the bytes to a hex string
representation of the bytes.
|
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 |
escapeHtml(String str)
Helper function to escape Strings for display in HTML pages.
|
static String |
getRandomString(Random rnd,
int minLength,
int maxLength)
Creates a random string with a length within the given interval.
|
static String |
getRandomString(Random rnd,
int minLength,
int maxLength,
char minValue,
char maxValue)
Creates a random string with a length within the given interval.
|
static byte[] |
hexStringToByte(String hex)
Given a hex string this will return the byte array corresponding to the
string .
|
static String |
readNullableString(DataInputView in)
Reads a String from the given input.
|
static String |
showControlCharacters(String str)
Replaces control characters by their escape-coded version.
|
static String |
stringifyException(Throwable e)
Makes a string representation of the exception.
|
static void |
writeNullableString(String str,
DataOutputView out)
Writes a String to the given output.
|
public static String stringifyException(Throwable e)
e
- the exception to stringifypublic static String byteToHexString(byte[] bytes, int start, int end)
bytes
- the bytes to convert in a hex stringstart
- start index, inclusivelyend
- end index, exclusivelyorg.apache.commons.codec.binary.Hex#encodeHexString(byte[])
public static String byteToHexString(byte[] bytes)
bytes
- the bytes to convert in a hex stringpublic static byte[] hexStringToByte(String hex)
hex
- the hex String arraypublic static String escapeHtml(String str)
str
- The string to escape.public static String arrayAwareToString(Object o)
Object.toString()
on the given object, unless the
object is an array. In that case, it will use the arrayToString(Object)
method to create a string representation of the array that includes all contained
elements.o
- The object for which to create the string representation.public static String arrayToString(Object array)
array
- The array to create a string representation for.IllegalArgumentException
- If the given object is no array.public static String showControlCharacters(String str)
str
- The string in which to replace the control characters.public static String getRandomString(Random rnd, int minLength, int maxLength)
rnd
- The random used to create the strings.minLength
- The minimum string length.maxLength
- The maximum string length (inclusive).public static String getRandomString(Random rnd, int minLength, int maxLength, char minValue, char maxValue)
rnd
- The random used to create the strings.minLength
- The minimum string length.maxLength
- The maximum string length (inclusive).minValue
- The minimum character value to occur.maxValue
- The maximum character value to occur.public static void writeNullableString(String str, DataOutputView out) throws IOException
readNullableString(DataInputView)
-str
- The string to write, or null.out
- The output to write to.IOException
- Throws if the writing or the serialization fails.public static String readNullableString(DataInputView in) throws IOException
writeNullableString(String, DataOutputView)
.in
- The input to read from.IOException
- Throws if the reading or the deserialization fails.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.