@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 |
concatenateWithAnd(String s1,
String s2)
If both string arguments are non-null, this method concatenates them with ' and '.
|
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 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 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()
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 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 argumentCopyright © 2014–2018 The Apache Software Foundation. All rights reserved.