DynamoDBUtils { public static byte[] encodeSortableBase64(final byte[] original) { final byte[] bytes = Base64.encode(original); for (int i = 0; i < bytes.length; i++) { bytes[i] = defaultToSortable[bytes[i]]; } return bytes; }  static byte[] getDynamoDBSafePartitionKey(final byte[] partitionKey); static byte[] getPrimaryId(final Map<String, AttributeValue> map); static byte[] getSecondaryId(final Map<String, AttributeValue> map); static byte[] getVisibility(final Map<String, AttributeValue> map); static byte[] getValue(final Map<String, AttributeValue> map); static byte[] encodeSortableBase64(final byte[] original); static byte[] decodeSortableBase64(final byte[] original); static final byte[] EMPTY_PARTITION_KEY; }
@Test public void testSortableBase64Sorting() { final List<byte[]> sortedBinary = Lists.newArrayList(); for (int i = 0; i < Short.MAX_VALUE; i += 100) { final byte[] bytes = new byte[2]; bytes[1] = (byte) (i & 0xff); bytes[0] = (byte) ((i >> 8) & 0xff); sortedBinary.add(bytes); } for (int i = Short.MIN_VALUE; i < 0; i += 100) { final byte[] bytes = new byte[2]; bytes[1] = (byte) (i & 0xff); bytes[0] = (byte) ((i >> 8) & 0xff); sortedBinary.add(bytes); } verifySorted(sortedBinary); final List<byte[]> encodedBinary = Lists.transform(sortedBinary, (binary) -> DynamoDBUtils.encodeSortableBase64(binary)); verifySorted(encodedBinary); }