public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
AMP_ENCODE |
static String |
APOS_ENCODE |
static String |
GT_ENCODE |
static String |
LT_ENCODE |
static String |
QUOTE_ENCODE |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
decodeBase64(String data)
Decodes a base64 String.
|
static String |
encodeBase64(byte[] data)
Encodes a byte array into a base64 String.
|
static String |
encodeBase64(byte[] data,
boolean lineBreaks)
Encodes a byte array into a bse64 String.
|
static String |
encodeBase64(byte[] data,
int offset,
int len,
boolean lineBreaks)
Encodes a byte array into a bse64 String.
|
static String |
encodeBase64(String data)
Encodes a String as a base64 String.
|
static String |
encodeHex(byte[] bytes)
Encodes an array of bytes as String representation of hexadecimal.
|
static CharSequence |
escapeForXML(String string)
Escapes all necessary characters in the String so that it can be used
in an XML doc.
|
static String |
escapeNode(String node)
Escapes the node portion of a JID according to "JID Escaping" (JEP-0106).
|
static String |
hash(String data)
Hashes a String using the SHA-1 algorithm and returns the result as a
String of hexadecimal numbers.
|
static boolean |
isEmpty(CharSequence cs)
Returns true if the given CharSequence is empty
|
static boolean |
isFullJID(String jid)
Returns true if jid is a full JID (i.e.
|
static boolean |
isNotEmpty(CharSequence cs)
Returns true if CharSequence is not null and is not empty, false otherwise
Examples:
isNotEmpty(null) - false
isNotEmpty("") - false
isNotEmpty(" ") - true
isNotEmpty("empty") - true
|
static boolean |
isNullOrEmpty(CharSequence cs)
Returns true if the given CharSequence is null or empty.
|
static int |
nullSafeCharSequenceComperator(CharSequence csOne,
CharSequence csTwo) |
static boolean |
nullSafeCharSequenceEquals(CharSequence csOne,
CharSequence csTwo) |
static String |
parseBareAddress(String XMPPAddress)
Returns the XMPP address with any resource information removed.
|
static String |
parseName(String XMPPAddress)
Returns the name portion of a XMPP address.
|
static String |
parseResource(String XMPPAddress)
Returns the resource portion of a XMPP address.
|
static String |
parseServer(String XMPPAddress)
Returns the server portion of a XMPP address.
|
static String |
randomString(int length)
Returns a random String of numbers and letters (lower and upper case)
of the specified length.
|
static String |
unescapeNode(String node)
Un-escapes the node portion of a JID according to "JID Escaping" (JEP-0106).
|
public static final String QUOTE_ENCODE
public static final String APOS_ENCODE
public static final String AMP_ENCODE
public static final String LT_ENCODE
public static final String GT_ENCODE
public StringUtils()
public static String parseName(String XMPPAddress)
XMPPAddress
- the XMPP address.public static String parseServer(String XMPPAddress)
XMPPAddress
- the XMPP address.public static String parseResource(String XMPPAddress)
XMPPAddress
- the XMPP address.public static String parseBareAddress(String XMPPAddress)
XMPPAddress
- the XMPP address.public static boolean isFullJID(String jid)
jid
- public static String escapeNode(String node)
Unescaped Character | Encoded Sequence |
<space> | \20 |
" | \22 |
& | \26 |
' | \27 |
/ | \2f |
: | \3a |
< | \3c |
> | \3e |
@ | \40 |
\ | \5c |
This process is useful when the node comes from an external source that doesn't conform to nodeprep. For example, a username in LDAP may be "Joe Smith". Because the <space> character isn't a valid part of a node, the username should be escaped to "Joe\20Smith" before being made into a JID (e.g. "joe\20smith@example.com" after case-folding, etc. has been applied).
All node escaping and un-escaping must be performed manually at the appropriate time; the JID class will not escape or un-escape automatically.
node
- the node.public static String unescapeNode(String node)
Escaping replaces characters prohibited by node-prep with escape sequences, as follows:
Unescaped Character | Encoded Sequence |
<space> | \20 |
" | \22 |
& | \26 |
' | \27 |
/ | \2f |
: | \3a |
< | \3c |
> | \3e |
@ | \40 |
\ | \5c |
This process is useful when the node comes from an external source that doesn't conform to nodeprep. For example, a username in LDAP may be "Joe Smith". Because the <space> character isn't a valid part of a node, the username should be escaped to "Joe\20Smith" before being made into a JID (e.g. "joe\20smith@example.com" after case-folding, etc. has been applied).
All node escaping and un-escaping must be performed manually at the appropriate time; the JID class will not escape or un-escape automatically.
node
- the escaped version of the node.public static CharSequence escapeForXML(String string)
string
- the string to escape.public static String hash(String data)
A hash is a one-way function -- that is, given an input, an output is easily computed. However, given the output, the input is almost impossible to compute. This is useful for passwords since we can store the hash and a hacker will then have a very hard time determining the original password.
data
- the String to compute the hash of.public static String encodeHex(byte[] bytes)
bytes
- an array of bytes to convert to a hex string.public static String encodeBase64(String data)
data
- a String to encode.public static String encodeBase64(byte[] data)
data
- a byte array to encode.public static String encodeBase64(byte[] data, boolean lineBreaks)
data
- The byte arry to encode.lineBreaks
- True if the encoding should contain line breaks and false if it should not.public static String encodeBase64(byte[] data, int offset, int len, boolean lineBreaks)
data
- The byte arry to encode.offset
- the offset of the bytearray to begin encoding at.len
- the length of bytes to encode.lineBreaks
- True if the encoding should contain line breaks and false if it should not.public static byte[] decodeBase64(String data)
data
- a base64 encoded String to decode.public static String randomString(int length)
The specified length must be at least one. If not, the method will return null.
length
- the desired length of the random String to return.public static boolean isNotEmpty(CharSequence cs)
cs
- checked CharSequencepublic static boolean isNullOrEmpty(CharSequence cs)
cs
- public static boolean isEmpty(CharSequence cs)
cs
- public static boolean nullSafeCharSequenceEquals(CharSequence csOne, CharSequence csTwo)
public static int nullSafeCharSequenceComperator(CharSequence csOne, CharSequence csTwo)