@Override public String getName(String id, String name) { return Base64.base64EncodeInt(name.hashCode()); } @Override
/** * @param value an integer to base64 encode. * @return the six digit long base64 encoded value of the integer. */ public static String base64EncodeInt(int value) { char[] c = new char[6]; for (int i = 0; i < 5; i++) { c[i] = Base64.toBase64((value >> (26 - i * 6)) & 0x3f); } c[5] = Base64.toBase64((value << 4) & 0x3f); return new String(c); } }
/** * Decodes the next VLQValue from the provided CharIterator. */ public static int decode(CharIterator in) { int result = 0; boolean continuation; int shift = 0; do { char c = in.next(); int digit = Base64.fromBase64(c); continuation = (digit & VLQ_CONTINUATION_BIT) != 0; digit &= VLQ_BASE_MASK; result = result + (digit << shift); shift = shift + VLQ_BASE_SHIFT; } while (continuation); return fromVLQSigned(result); } }
/** * Decodes the next VLQValue from the provided CharIterator. */ public static int decode(CharIterator in) { int result = 0; boolean continuation; int shift = 0; do { char c = in.next(); int digit = Base64.fromBase64(c); continuation = (digit & VLQ_CONTINUATION_BIT) != 0; digit &= VLQ_BASE_MASK; result = result + (digit << shift); shift = shift + VLQ_BASE_SHIFT; } while (continuation); return fromVLQSigned(result); } }
/** * @param value an integer to base64 encode. * @return the six digit long base64 encoded value of the integer. */ public static String base64EncodeInt(int value) { char[] c = new char[6]; for (int i = 0; i < 5; i++) { c[i] = Base64.toBase64((value >> (26 - i * 6)) & 0x3f); } c[5] = Base64.toBase64((value << 4) & 0x3f); return new String(c); } }
@Override public String getName(String id, String name) { return Base64.base64EncodeInt(name.hashCode()); } @Override
/** * Writes a VLQ encoded value to the provide appendable. * @throws IOException */ public static void encode(Appendable out, int value) throws IOException { value = toVLQSigned(value); do { int digit = value & VLQ_BASE_MASK; value >>>= VLQ_BASE_SHIFT; if (value > 0) { digit |= VLQ_CONTINUATION_BIT; } out.append(Base64.toBase64(digit)); } while (value > 0); }
/** * Writes a VLQ encoded value to the provide appendable. * @throws IOException */ public static void encode(Appendable out, int value) throws IOException { value = toVLQSigned(value); do { int digit = value & VLQ_BASE_MASK; value >>>= VLQ_BASE_SHIFT; if (value > 0) { digit |= VLQ_CONTINUATION_BIT; } out.append(Base64.toBase64(digit)); } while (value > 0); }