@PublicEvolving public final class StringUtils extends Object
限定符和类型 | 字段和说明 |
---|---|
static String[] |
EMPTY_STRING_ARRAY
An empty string array.
|
限定符和类型 | 方法和说明 |
---|---|
static String |
arrayAwareToString(Object o)
Converts the given object into a string representation by calling
Object.toString()
and formatting (possibly nested) arrays and null . |
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 |
concatenateWithAnd(String s1,
String s2)
If both string arguments are non-null, this method concatenates them with ' and '.
|
static String |
generateRandomAlphanumericString(Random rnd,
int length)
Creates a random alphanumeric string of given length.
|
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 boolean |
isNullOrWhitespaceOnly(String str)
Checks if the string is null, empty, or contains only whitespace characters.
|
static String |
readNullableString(DataInputView in)
Reads a String from the given input.
|
static String |
readString(DataInputView in)
Reads a non-null String from the given input.
|
static String |
showControlCharacters(String str)
Replaces control characters by their escape-coded version.
|
static String |
toQuotedListString(Object[] values)
Generates a string containing a comma-separated list of values in double-quotes.
|
static void |
writeNullableString(String str,
DataOutputView out)
Writes a String to the given output.
|
static void |
writeString(String str,
DataOutputView out)
Writes a String to the given output.
|
public static final String[] EMPTY_STRING_ARRAY
public static String byteToHexString(byte[] bytes, int start, int end)
bytes
- the bytes to convert in a hex stringstart
- start index, inclusivelyend
- end index, exclusivelypublic 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 arrayAwareToString(Object o)
Object.toString()
and formatting (possibly nested) arrays and null
.
See Arrays.deepToString(Object[])
for more information about the used format.
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 String generateRandomAlphanumericString(Random rnd, int length)
rnd
- The random number generator to use.length
- The number of alphanumeric characters to append.public static void writeString(@Nonnull String str, DataOutputView out) throws IOException
readString(DataInputView)
.str
- The string to writeout
- The output to write toIOException
- Thrown, if the writing or the serialization fails.public static String readString(DataInputView in) throws IOException
in
- The input to read fromIOException
- Thrown, if the reading or the deserialization fails.public static void writeNullableString(@Nullable String str, DataOutputView out) throws IOException
readNullableString(DataInputView)
-str
- The string to write, or null.out
- The output to write to.IOException
- Thrown, if the writing or the serialization fails.@Nullable public static String readNullableString(DataInputView in) throws IOException
writeNullableString(String, DataOutputView)
.in
- The input to read from.IOException
- Thrown, if the reading or the deserialization fails.public static boolean isNullOrWhitespaceOnly(String str)
Character.isWhitespace(char)
.str
- The string to check@Nullable public static String concatenateWithAnd(@Nullable String s1, @Nullable String s2)
s1
- The first string arguments2
- The second string argumentpublic static String toQuotedListString(Object[] values)
Object.toString()
method for each element in the
given array. Null values are skipped.values
- array of elements for the listCopyright © 2014–2022 The Apache Software Foundation. All rights reserved.