S3WritableByteChannel implements WritableByteChannel { @Override public int write(ByteBuffer sourceBuffer) throws IOException { if (!isOpen()) { throw new ClosedChannelException(); } int totalBytesWritten = 0; while (sourceBuffer.hasRemaining()) { int bytesWritten = Math.min(sourceBuffer.remaining(), uploadBuffer.remaining()); totalBytesWritten += bytesWritten; byte[] copyBuffer = new byte[bytesWritten]; sourceBuffer.get(copyBuffer); uploadBuffer.put(copyBuffer); md5.update(copyBuffer); if (!uploadBuffer.hasRemaining() || sourceBuffer.hasRemaining()) { flush(); } } return totalBytesWritten; } S3WritableByteChannel(AmazonS3 amazonS3, S3ResourceId path, String contentType, S3Options options); @Override int write(ByteBuffer sourceBuffer); @Override boolean isOpen(); @Override void close();  }
@Test public void write() throws IOException { writeFromOptions(s3Options()); writeFromOptions(s3OptionsWithSSEAlgorithm()); writeFromOptions(s3OptionsWithSSECustomerKey()); writeFromOptions(s3OptionsWithSSEAwsKeyManagementParams()); expected.expect(IllegalArgumentException.class); writeFromOptions(s3OptionsWithMultipleSSEOptions()); }