/** * The real compactor. */ private String compact(final long msb, final long lsb, final BaseNCodec baseN, final int compactLen) { final byte[] bytes = new byte[BYTES_PER_2_LONGS]; int i = BYTES_PER_2_LONGS; long x = lsb; while (i > BYTES_PER_LONG) { bytes[--i] = (byte)x; x >>>= Byte.SIZE; } x = msb; while (i > 0) { bytes[--i] = (byte)x; x >>>= Byte.SIZE; } // strips any the trailing ====== return baseN.encodeAsString(bytes).substring(0, compactLen); }
/** * The real expander. */ private long[] expand(final String compactUuid, final BaseNCodec baseN) { final byte[] bytes = baseN.decode(compactUuid); if (bytes.length != BYTES_PER_2_LONGS) { throw new IllegalArgumentException("Not a compact uuid string: " + compactUuid); } int i = 0; long msb = bytes[i++]; while (i < BYTES_PER_LONG) { msb = msb << Byte.SIZE | (bytes[i++] & LONG_BYTE_MASK); } long lsb = bytes[i++]; while (i < BYTES_PER_2_LONGS) { lsb = lsb << Byte.SIZE | (bytes[i++] & LONG_BYTE_MASK); } return new long[] { msb, lsb }; }
protected static WebArchive getDefaultDeployment(TestContext context) { context.setAppEngineWebXmlFile("appengine-web-with-logging-properties.xml"); WebArchive war = getTckDeployment(context); war.addClasses(LoggingTestBase.class, TestBase.class) // classes for Base64.isBase64() .addClasses(Base64.class, BaseNCodec.class) .addClasses(BinaryEncoder.class, Encoder.class) .addClasses(BinaryDecoder.class, Decoder.class) .addClasses(EncoderException.class, DecoderException.class) .addAsWebInfResource("currentTimeUsec.jsp") .addAsWebInfResource("doNothing.jsp") .addAsWebInfResource("storeTestData.jsp") .addAsWebInfResource("throwException.jsp") .addAsWebInfResource("log4j-test.properties") .addAsWebInfResource("logging-all.properties"); return war; }
protected static WebArchive getHelperDeployment() { WebArchive war = getTckDeployment(); war.addClass(DatastoreHelperTestBase.class) .addClasses(Base64.class, BaseNCodec.class) .addClasses(BinaryEncoder.class, Encoder.class) .addClasses(BinaryDecoder.class, Decoder.class) .addClasses(EncoderException.class, DecoderException.class); return war; }
public static String base64UrlEncode(byte[] input) { Base64 base64 = new Base64(BaseNCodec.MIME_CHUNK_SIZE, EMPTY_BYTE_ARRAY, true); return base64.encodeAsString(input); }