001package io.ebean.util;
002
003/**
004 * Integer to base64 encoder.
005 */
006public final class EncodeB64 {
007
008  private static final int radix = 1 << 6;
009  private static final int mask = radix - 1;
010
011  /**
012   * Convert the integer to unsigned base 64.
013   */
014  public static String enc(int i) {
015    char[] buf = new char[32];
016    int charPos = 32;
017    do {
018      buf[--charPos] = intToBase64[i & mask];
019      i >>>= 6;
020    } while (i != 0);
021
022    return new String(buf, charPos, (32 - charPos));
023  }
024
025  private static final char intToBase64[] = {
026    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
027    'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
028    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
029    'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
030    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'
031  };
032}