public class TokenUtil extends Object
A utility class for converting APNS device tokens between byte arrays and hexadecimal strings.
| Modifier and Type | Method and Description |
|---|---|
static String |
tokenBytesToString(byte[] tokenBytes)
Converts an array of bytes into a string of hexadecimal characters representing the values in the array.
|
static byte[] |
tokenStringToByteArray(String tokenString)
Converts a string of hexadecimal characters into a byte array.
|
public static byte[] tokenStringToByteArray(String tokenString) throws MalformedTokenStringException
Converts a string of hexadecimal characters into a byte array. All non-hexadecimal characters (i.e. 0-9 and
A-F) are ignored in the conversion. Note that this means that
TokenUtil.tokenBytesToString(TokenUtil.tokenStringToByteArray(tokenString)) may be different from
tokenString.
As an example, a valid token string may look something like this: <740f4707 61bb78ad>. This method
would return a byte array with the following values: [0x74 0x0f 0x47 0x07 0x61 0xbb 0x78 0xad].
tokenString - a string of hexadecimal characters to interpret as a byte arrayMalformedTokenStringException - if the given token string could not be parsed as an APNs tokenNullPointerException - if the given string is nullpublic static String tokenBytesToString(byte[] tokenBytes)
Converts an array of bytes into a string of hexadecimal characters representing the values in the array. For
example, calling this method on a byte array with the values [0x01 0x23 0x45 0x67 0x89 0xab] would return
"0123456789ab". No guarantees are made as to the case of the returned string.
tokenBytes - an array of bytes to represent as a stringNullPointerException - if the given byte array is nullCopyright © 2013–2015 RelayRides. All rights reserved.