public class StringUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
__ISO_8859_1 |
static String |
__LINE_SEPARATOR
Deprecated.
use
System.lineSeparator() instead |
static String |
__UTF16 |
static String |
__UTF8 |
static String |
ALL_INTERFACES |
static String |
CRLF |
static char[] |
lowercases |
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
append(StringBuilder buf,
byte b,
int base)
append hex digit
|
static void |
append(StringBuilder buf,
String s,
int offset,
int length)
Append substring to StringBuilder
|
static void |
append2digits(StringBuffer buf,
int i)
Append 2 digits (zero padded) to the StringBuffer
|
static void |
append2digits(StringBuilder buf,
int i)
Append 2 digits (zero padded) to the StringBuilder
|
static String[] |
arrayFromString(String s) |
static String |
asciiToLowerCase(String s)
fast lower case conversion.
|
static boolean |
endsWithIgnoreCase(String s,
String w) |
static boolean |
equals(String s,
char[] buf,
int offset,
int length) |
static byte[] |
getBytes(String s) |
static byte[] |
getBytes(String s,
String charset) |
static byte[] |
getUtf8Bytes(String s) |
static int |
indexFrom(String s,
String chars)
returns the next index of a character from the chars string
|
static boolean |
isBlank(String str)
Test if a string is null or only has whitespace characters in it.
|
static boolean |
isNotBlank(String str)
Test if a string is not null and contains at least 1 non-whitespace characters in it.
|
static boolean |
isUTF8(String charset) |
static String |
nonNull(String s)
Return a non null string.
|
static String |
normalizeCharset(String s)
Convert alternate charset names (eg utf8) to normalized
name (eg UTF-8).
|
static String |
normalizeCharset(String s,
int offset,
int length)
Convert alternate charset names (eg utf8) to normalized
name (eg UTF-8).
|
static String |
printable(byte[] b) |
static String |
printable(String name) |
static String |
replace(String s,
String sub,
String with)
replace substrings within string.
|
static String |
sidBytesToString(byte[] sidBytes)
Converts a binary SID to a string SID
http://en.wikipedia.org/wiki/Security_Identifier
S-1-IdentifierAuthority-SubAuthority1-SubAuthority2-...-SubAuthorityn
|
static byte[] |
sidStringToBytes(String sidString)
Converts a string SID to a binary SID
http://en.wikipedia.org/wiki/Security_Identifier
S-1-IdentifierAuthority-SubAuthority1-SubAuthority2-...-SubAuthorityn
|
static boolean |
startsWithIgnoreCase(String s,
String w) |
static int |
toInt(String string,
int from)
Convert String to an integer.
|
static long |
toLong(String string)
Convert String to an long.
|
static String |
toString(byte[] b,
int offset,
int length,
String charset) |
static String |
toUTF8String(byte[] b,
int offset,
int length) |
static String |
truncate(String str,
int maxSize)
Truncate a string to a max size.
|
static String |
unquote(String s)
Remove single or double quotes.
|
static String |
valueOf(Object object)
The String value of an Object
|
public static final String ALL_INTERFACES
public static final String CRLF
@Deprecated public static final String __LINE_SEPARATOR
System.lineSeparator()
insteadpublic static final String __ISO_8859_1
public static final String __UTF8
public static final String __UTF16
public static final char[] lowercases
public static String normalizeCharset(String s)
s
- the charset to normalizepublic static String normalizeCharset(String s, int offset, int length)
s
- the charset to normalizeoffset
- the offset in the charsetlength
- the length of the charset in the input parampublic static String asciiToLowerCase(String s)
s
- the string to convertpublic static int indexFrom(String s, String chars)
s
- the input string to searchchars
- the chars to look forpublic static String replace(String s, String sub, String with)
s
- the input stringsub
- the string to look forwith
- the string to replace withpublic static String unquote(String s)
s
- the input stringpublic static void append(StringBuilder buf, String s, int offset, int length)
buf
- StringBuilder to append tos
- String to append fromoffset
- The offset of the substringlength
- The length of the substringpublic static void append(StringBuilder buf, byte b, int base)
buf
- the buffer to append tob
- the byte to appendbase
- the base of the hex output (almost always 16).public static void append2digits(StringBuffer buf, int i)
buf
- the buffer to append toi
- the value to appendpublic static void append2digits(StringBuilder buf, int i)
buf
- the buffer to append toi
- the value to appendpublic static String nonNull(String s)
s
- Stringpublic static boolean equals(String s, char[] buf, int offset, int length)
public static String toUTF8String(byte[] b, int offset, int length)
public static boolean isBlank(String str)
Note: uses codepoint version of Character.isWhitespace(int)
to support Unicode better.
isBlank(null) == true isBlank("") == true isBlank("\r\n") == true isBlank("\t") == true isBlank(" ") == true isBlank("a") == false isBlank(".") == false isBlank(";\n") == false
str
- the string to test.public static boolean isNotBlank(String str)
Note: uses codepoint version of Character.isWhitespace(int)
to support Unicode better.
isNotBlank(null) == false isNotBlank("") == false isNotBlank("\r\n") == false isNotBlank("\t") == false isNotBlank(" ") == false isNotBlank("a") == true isNotBlank(".") == true isNotBlank(";\n") == true
str
- the string to test.public static boolean isUTF8(String charset)
public static String printable(byte[] b)
public static byte[] getBytes(String s)
public static byte[] getUtf8Bytes(String s)
public static String sidBytesToString(byte[] sidBytes)
sidBytes
- the SID bytes to build frompublic static byte[] sidStringToBytes(String sidString)
sidString
- the string SIDpublic static int toInt(String string, int from)
string
- A String containing an integer.from
- The index to start parsing frompublic static long toLong(String string)
string
- A String containing an integer.public static String truncate(String str, int maxSize)
str
- the string to possibly truncatemaxSize
- the maximum size of the stringstr
param is null, then the returned string will also be null.public static String valueOf(Object object)
This method calls String.valueOf(Object)
unless the object is null,
in which case null is returned
object
- The objectCopyright © 1995-2015 Webtide. All Rights Reserved.