com.relayrides.pushy.apns.util
Class TokenUtil

java.lang.Object
  extended by com.relayrides.pushy.apns.util.TokenUtil

public class TokenUtil
extends Object

A utility class for converting APNS device tokens between byte arrays and hexadecimal strings.

Author:
Jon Chambers

Method Summary
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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

tokenStringToByteArray

public static byte[] tokenStringToByteArray(String tokenString)

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].

Parameters:
tokenString - a string of hexadecimal characters to interpret as a byte array
Returns:
a byte array containing the values represented in the token string

tokenBytesToString

public 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.

Parameters:
tokenBytes - an array of bytes to represent as a string
Returns:
a string of hexadecimal characters representing the values in the given byte array


Copyright © 2013 RelayRides. All rights reserved.