@Test public void toByteArray() throws ReflectiveOperationException { final byte[] expected = new byte[] {0, 1, 2, 3, 4, 5}; assertToByteArray("Wrap", expected, ByteBuffer.wrap(expected)); assertToByteArray("Wrap-RO", expected, ByteBuffer.wrap(expected).asReadOnlyBuffer()); assertToByteArray("Wrap-Truncated-Sliced", expected, ByteBuffer.wrap(new byte[] {0, 1, 2, 3, 4, 5, 6}, 0, 6).slice()); assertToByteArray("Wrap-Offset-Sliced", expected, ByteBuffer.wrap(new byte[] {6, 0, 1, 2, 3, 4, 5, 6}, 1, 6).slice()); assertToByteArray("Wrap-Truncated", expected, ByteBuffer.wrap(new byte[] {0, 1, 2, 3, 4, 5, 6}, 0, 6)); assertToByteArray("Wrap-Offset", expected, ByteBuffer.wrap(new byte[] {6, 0, 1, 2, 3, 4, 5, 6}, 1, 6)); ByteBuffer buff = ByteBuffer.allocate(expected.length + 10); buff.put(expected); buff.flip(); assertToByteArray("Normal", expected, buff); buff = ByteBuffer.allocateDirect(expected.length + 10); buff.put(expected); buff.flip(); assertToByteArray("Direct", expected, buff); }
private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; }
DynamoDbEncryptor implements DynamoDbEncryptionClient { private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } }
DynamoDbEncryptor implements DynamoDbEncryptionClient { private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider, String descriptionBase); protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider); }
DynamoDbEncryptor implements DynamoDbEncryptionClient { private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider, String descriptionBase); protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider); static Builder builder(); @Override Map<String, AttributeValue> encryptRecord(Map<String, AttributeValue> record,
                                                     DynamoDbEncryptionConfiguration configuration); @Override Map<String, AttributeValue> decryptRecord(Map<String, AttributeValue> record,
                                                     DynamoDbEncryptionConfiguration configuration); }
DynamoDbEncryptor implements DynamoDbEncryptionClient { private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider, String descriptionBase); protected  DynamoDbEncryptor(EncryptionMaterialsProvider provider); static Builder builder(); @Override Map<String, AttributeValue> encryptRecord(Map<String, AttributeValue> record,
                                                     DynamoDbEncryptionConfiguration configuration); @Override Map<String, AttributeValue> decryptRecord(Map<String, AttributeValue> record,
                                                     DynamoDbEncryptionConfiguration configuration);  }