try {
if (b.getEntries().isEmpty()) {
if (!connection.getConnection().deleteObject(rootS3Bucket, b.getBucketName()).get())
throw new S3ConnectionException(String.format("Could not delete object [%2s] in s3bucket [%1s] ", rootS3Bucket.getName(), b.getBucketName()));
} else {
S3Object s3Object = new S3Object();
s3Object.setKey(b.getBucketName());
s3Object.setContent(connection.marshaller.objectToByteBuffer(b));
s3Object.setContentType("application/octet-string");
String id = connection.getConnection().addObject(rootS3Bucket, s3Object).get();
assert id != null : String.format("Should have received an id for entry %1s:%2s ", rootS3Bucket.getName(), b.getBucketName());
}
} catch (Exception ex) {
throw connection.convertToS3ConnectionException("Exception while saving bucket " + b, ex);