public class Strings extends Object
String
processing.Modifier and Type | Method and Description |
---|---|
static byte[] |
asciiBytes(String s)
Create a byte[] representation of the given string, using ASCII encoding.
|
static String |
asciiString(byte[] bytes)
Construct a new String from the given input bytes, using ASCII encoding.
|
static void |
assertNotEmpty(String name,
String value)
Checks whether the given
value is an empty String |
static String |
create(InputStream is)
Create a string by fully reading the supplied input stream using the default platform encoding.
|
static String |
create(InputStream is,
String encoding)
Create a string by fully reading the supplied input stream using the specified encoding.
|
static boolean |
empty(String s)
Check whether the given
String is empty or not. |
static boolean |
emptyTrim(String s)
Check whether the given
String is empty or not. |
static int |
indexOf(byte[] buffer,
String matchString,
int fromIndex)
Finds the first occurrance of the given String in the given buffer.
|
static int |
lastIndexOf(byte[] buffer,
String matchString,
int toIndex)
Finds the last occurrance of the given String in the given buffer.
|
static <T> T |
parsePrimitive(Class<T> targetType,
String valueString)
Parses the valueString based on given targetType and returns a value object decoded from given
valueString.
|
static String |
replaceAll(String source,
String pattern,
String replacement)
Replace a String inside of a String.
|
static String |
toFixedLength(String s,
int length,
char padding)
Format the string into a fixed-length representation by either trimming it to the required size
(if it is longer) or padding it at the end with the given padding character.
|
static String |
toHex(byte[] data)
Convert byte array to hex string.
|
static String |
toHex(byte[] data,
int offset,
int len)
Convert byte array to hex string.
|
static String |
trimCharacter(String stringToTrim,
char charToRemove)
Returns a copy of the string, with leading and trailing given parameter character omitted.
|
static String |
trimLeadingCharacter(String stringToTrim,
char charToRemove)
Returns a copy of the string, with leading given parameter character omitted
|
static String |
trimTrailingCharacter(String stringToTrim,
char charToRemove)
Returns a copy of the string, with trailing given parameter character omitted.
|
static byte[] |
utf16Bytes(String s) |
static byte[] |
utf8Bytes(String s)
Create a byte[] representation of the given string, using UTF-8 encoding.
|
static String |
utf8String(byte[] bytes)
Construct a new String from the given input bytes, using UTF-8 encoding.
|
static boolean |
whitespace(String s)
Check whether the given
String only contains whitespace characters . |
public static boolean empty(String s)
public static boolean emptyTrim(String s)
String
is empty or not. This method basically works like
empty(String)
but with the addition that the String
will be
trimmed
and checked if it contains any non whitespace character.public static boolean whitespace(String s)
String
only contains whitespace characters
. This method is null
-safe. null
will be
interpreted as whitespaces
- the String
true
if the String
consists only of
whitespace characters
or null.public static String replaceAll(String source, String pattern, String replacement)
source
- the String to replace stuff itpattern
- the String to replacereplacement
- the replacementpublic static String toHex(byte[] data)
data
- byte arraypublic static String toHex(byte[] data, int offset, int len)
data
- byte arrayoffset
- from offsetlen
- lengthpublic static String trimLeadingCharacter(String stringToTrim, char charToRemove)
stringToTrim
- the string to trimcharToRemove
- the character to removepublic static String trimTrailingCharacter(String stringToTrim, char charToRemove)
stringToTrim
- the string to trimcharToRemove
- the character to removepublic static String trimCharacter(String stringToTrim, char charToRemove)
stringToTrim
- the string to trimcharToRemove
- the character to removepublic static int indexOf(byte[] buffer, String matchString, int fromIndex)
buffer
- The buffer to search for the given match String.matchString
- The character sequence to find in the given bufferfromIndex
- The index of the position to start the search withpublic static int lastIndexOf(byte[] buffer, String matchString, int toIndex)
buffer
- The buffer to search for the given match String.matchString
- The character sequence to find in the given buffertoIndex
- The index of the position to end the search withpublic static String create(InputStream is) throws IOException
is
- IOException
public static String create(InputStream is, String encoding) throws IOException
is
- encoding
- IOException
public static void assertNotEmpty(String name, String value)
value
is an empty String
name
- value
- public static <T> T parsePrimitive(Class<T> targetType, String valueString)
Integer.TYPE
as targetType, the returned value will be wrapped as the corresponding
object type such as Integer
.targetType
- defines the expected return value type. Supported targetTypes are String,
Byte, Short, Integer, Long, Double, Float, Boolean, Character, Enum, Color, Font.valueString
- the value as stringIllegalArgumentException
- if the targetType is null
or the valueString is
badly formatted.public static String toFixedLength(String s, int length, char padding)
s
- the stringlength
- the desired lengthpadding
- the padding characterpublic static String asciiString(byte[] bytes)
bytes
- the bytes to construct a String
frompublic static String utf8String(byte[] bytes)
bytes
- the bytes to construct a String
frompublic static byte[] asciiBytes(String s)
s
- the String
to generate a byte[] representation ofpublic static byte[] utf8Bytes(String s)
s
- the String
to generate a byte[] representation ofpublic static byte[] utf16Bytes(String s)
s
- the String to be encodedCopyright © 2024 levigo holding gmbh. All rights reserved.