Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Created April 15, 2015 02:38
Show Gist options
  • Save tklee1975/29595d20f9cbbbd3d665 to your computer and use it in GitHub Desktop.
Save tklee1975/29595d20f9cbbbd3d665 to your computer and use it in GitHub Desktop.
Token Generator; Example usage: pageToken for a long result set like the APIs of Google Place API
public static String generateToken(String prefix, int uid)
{
long now = System.currentTimeMillis();
// Shorten integer values
String nowStr = Base64.encodeLong(now);
String uidStr = Base64.encodeInt(uid);
// Concatenate
String token = prefix + nowStr + uidStr;
// replace some special symbols
token = token.replaceAll("[\n =]", "_");
return token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment