|
Smack | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jivesoftware.smack.util.StringUtils
public class StringUtils
A collection of utility methods for String objects.
Field Summary | |
---|---|
static java.text.DateFormat |
XEP_0082_UTC_FORMAT
Deprecated. This public version will be removed in favor of using the methods defined within this class. |
Method Summary | |
---|---|
static byte[] |
decodeBase64(java.lang.String data)
Decodes a base64 String. |
static java.lang.String |
encodeBase64(byte[] data)
Encodes a byte array into a base64 String. |
static java.lang.String |
encodeBase64(byte[] data,
boolean lineBreaks)
Encodes a byte array into a bse64 String. |
static java.lang.String |
encodeBase64(byte[] data,
int offset,
int len,
boolean lineBreaks)
Encodes a byte array into a bse64 String. |
static java.lang.String |
encodeBase64(java.lang.String data)
Encodes a String as a base64 String. |
static java.lang.String |
encodeHex(byte[] bytes)
Encodes an array of bytes as String representation of hexadecimal. |
static java.lang.String |
escapeForXML(java.lang.String string)
Escapes all necessary characters in the String so that it can be used in an XML doc. |
static java.lang.String |
escapeNode(java.lang.String node)
Escapes the node portion of a JID according to "JID Escaping" (JEP-0106). |
static java.lang.String |
formatDate(java.util.Date toFormat,
DateFormatType type)
|
static java.lang.String |
formatXEP0082Date(java.util.Date date)
Formats a Date into a XEP-0082 - XMPP Date and Time Profiles string. |
static java.lang.String |
hash(java.lang.String data)
Hashes a String using the SHA-1 algorithm and returns the result as a String of hexadecimal numbers. |
static boolean |
isFullJID(java.lang.String jid)
Returns true if jid is a full JID (i.e. |
static java.lang.String |
parseBareAddress(java.lang.String XMPPAddress)
Returns the XMPP address with any resource information removed. |
static java.util.Date |
parseDate(java.lang.String dateString)
Parses the given date string in either of the three profiles of XEP-0082 - XMPP Date and Time Profiles or XEP-0091 - Legacy Delayed Delivery format. |
static java.lang.String |
parseName(java.lang.String XMPPAddress)
Returns the name portion of a XMPP address. |
static java.lang.String |
parseResource(java.lang.String XMPPAddress)
Returns the resource portion of a XMPP address. |
static java.lang.String |
parseServer(java.lang.String XMPPAddress)
Returns the server portion of a XMPP address. |
static java.util.Date |
parseXEP0082Date(java.lang.String dateString)
Deprecated. Use parseDate(String) instead. |
static java.lang.String |
randomString(int length)
Returns a random String of numbers and letters (lower and upper case) of the specified length. |
static java.lang.String |
unescapeNode(java.lang.String node)
Un-escapes the node portion of a JID according to "JID Escaping" (JEP-0106). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.text.DateFormat XEP_0082_UTC_FORMAT
Date formats are not synchronized. Since multiple threads access the format concurrently, it
must be synchronized externally or you can use the convenience methods
parseXEP0082Date(String)
and formatXEP0082Date(Date)
.
Method Detail |
---|
public static java.util.Date parseXEP0082Date(java.lang.String dateString) throws java.text.ParseException
parseDate(String)
instead.
dateString
- the date string to parse
java.text.ParseException
- if the specified string cannot be parsedpublic static java.util.Date parseDate(java.lang.String dateString) throws java.text.ParseException
This method uses internal date formatters and is thus threadsafe.
dateString
- the date string to parse
java.text.ParseException
- if the specified string cannot be parsedpublic static java.lang.String formatXEP0082Date(java.util.Date date)
date
- the time value to be formatted into a time string
public static java.lang.String formatDate(java.util.Date toFormat, DateFormatType type)
public static java.lang.String parseName(java.lang.String XMPPAddress)
XMPPAddress
- the XMPP address.
public static java.lang.String parseServer(java.lang.String XMPPAddress)
XMPPAddress
- the XMPP address.
public static java.lang.String parseResource(java.lang.String XMPPAddress)
XMPPAddress
- the XMPP address.
public static java.lang.String parseBareAddress(java.lang.String XMPPAddress)
XMPPAddress
- the XMPP address.
public static boolean isFullJID(java.lang.String jid)
jid
-
public static java.lang.String escapeNode(java.lang.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 java.lang.String unescapeNode(java.lang.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 java.lang.String escapeForXML(java.lang.String string)
string
- the string to escape.
public static java.lang.String hash(java.lang.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 java.lang.String encodeHex(byte[] bytes)
bytes
- an array of bytes to convert to a hex string.
public static java.lang.String encodeBase64(java.lang.String data)
data
- a String to encode.
public static java.lang.String encodeBase64(byte[] data)
data
- a byte array to encode.
public static java.lang.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 java.lang.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(java.lang.String data)
data
- a base64 encoded String to decode.
public static java.lang.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.
|
Smack | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |