|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.levigo.util.base.Strings
public class Strings
Utility methods for String
processing.
Method Summary | ||
---|---|---|
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
|
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 . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean empty(String s)
String
is empty or not. This method is null
-safe.
null
will be interpreted as an empty String
s
- the String
to be checked.
true
if the String
is either null
or has zero lengthpublic 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.
s
- the String
to be checked.
true
if the String
is either null
or has zero length
after trimming
public static boolean whitespace(String s)
String
only contains whitespace characters
. This method is null
-safe. null
will be
interpreted as whitespace
s
- 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 replacement
public static String toHex(byte[] data)
data
- byte array
public static String toHex(byte[] data, int offset, int len)
data
- byte arrayoffset
- from offsetlen
- length
public static String trimLeadingCharacter(String stringToTrim, char charToRemove)
stringToTrim
- the string to trimcharToRemove
- the character to remove
public static String trimTrailingCharacter(String stringToTrim, char charToRemove)
stringToTrim
- the string to trimcharToRemove
- the character to remove
public static String trimCharacter(String stringToTrim, char charToRemove)
stringToTrim
- the string to trimcharToRemove
- the character to remove
public 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 with
public 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 with
public 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 string
IllegalArgumentException
- 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 character
public static String asciiString(byte[] bytes)
bytes
- the bytes to construct a String
from
public static String utf8String(byte[] bytes)
bytes
- the bytes to construct a String
from
public static byte[] asciiBytes(String s)
s
- the String
to generate a byte[] representation of
public static byte[] utf8Bytes(String s)
s
- the String
to generate a byte[] representation of
public static byte[] utf16Bytes(String s)
s
- the String to be encoded
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |