diff --git a/api/src/main/java/io/minio/BaseS3Client.java b/api/src/main/java/io/minio/BaseS3Client.java index 87c757631..6336a1345 100644 --- a/api/src/main/java/io/minio/BaseS3Client.java +++ b/api/src/main/java/io/minio/BaseS3Client.java @@ -527,11 +527,10 @@ private void onResponse(final Response response) throws IOException { /** Execute HTTP request asynchronously for given args and parameters. */ protected CompletableFuture executeAsync(Http.S3Request s3request) { return getRegion(s3request.bucket(), s3request.region()) - .thenCompose( - location -> { - s3request.args().setLocation(location); - return executeAsync(s3request, location); - }); + .thenCompose(location -> { + s3request.args().setLocation(location); + return executeAsync(s3request, location); + }); } /** Execute asynchronously GET HTTP request for given parameters. */ @@ -559,20 +558,18 @@ protected CompletableFuture executeHeadAsync( .args(args) .build(); return executeAsync(s3request) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException - && ((ErrorResponseException) e).errorResponse().code().equals(RETRY_HEAD)) { - return null; - } - throw new CompletionException(e); - }) - .thenCompose( - response -> { - if (response != null) return CompletableFuture.completedFuture(response); - return executeAsync(s3request); - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException + && ((ErrorResponseException) e).errorResponse().code().equals(RETRY_HEAD)) { + return null; + } + throw new CompletionException(e); + }) + .thenCompose(response -> { + if (response != null) return CompletableFuture.completedFuture(response); + return executeAsync(s3request); + }); } /** Execute asynchronously DELETE HTTP request for given parameters. */ @@ -586,11 +583,10 @@ protected CompletableFuture executeDeleteAsync( .queryParams(queryParams) .args(args) .build()) - .thenApply( - response -> { - if (response != null) response.body().close(); - return response; - }); + .thenApply(response -> { + if (response != null) response.body().close(); + return response; + }); } /** Execute asynchronously POST HTTP request for given parameters. */ @@ -678,19 +674,14 @@ public CompletableFuture abortMultipartUpload( AbortMultipartUploadArgs args) { checkArgs(args); return executeDeleteAsync(args, null, new Http.QueryParameters(Http.UPLOAD_ID, args.uploadId())) - .thenApply( - response -> { - try { - return new AbortMultipartUploadResponse( - response.headers(), - args.bucket(), - args.location(), - args.object(), - args.uploadId()); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return new AbortMultipartUploadResponse( + response.headers(), args.bucket(), args.location(), args.object(), args.uploadId()); + } finally { + response.close(); + } + }); } private CompletableFuture completeMultipartUpload( @@ -700,87 +691,84 @@ private CompletableFuture completeMultipartUpload( args.ssec() == null ? null : args.ssec().headers(), new Http.QueryParameters(Http.UPLOAD_ID, args.uploadId()), body) - .thenApply( - response -> { + .thenApply(response -> { + try { + String bodyContent = response.body().string(); + bodyContent = bodyContent.trim(); + if (!bodyContent.isEmpty()) { try { - String bodyContent = response.body().string(); - bodyContent = bodyContent.trim(); - if (!bodyContent.isEmpty()) { - try { - if (Xml.validate(ErrorResponse.class, bodyContent)) { - ErrorResponse errorResponse = Xml.unmarshal(ErrorResponse.class, bodyContent); - throw new CompletionException( - new ErrorResponseException(errorResponse, response, null)); - } - } catch (XmlParserException e) { - // As it is not message, fallback to parse CompleteMultipartUploadOutput - // XML. - } - - try { - CompleteMultipartUploadResult result = - Xml.unmarshal(CompleteMultipartUploadResult.class, bodyContent); - return new ObjectWriteResponse( - response.headers(), - result.bucket(), - result.location(), - result.object(), - result.etag(), - response.header("x-amz-version-id"), - result); - } catch (XmlParserException e) { - // As this CompleteMultipartUpload REST call succeeded, just log it. - Logger.getLogger(BaseS3Client.class.getName()) - .warning( - "S3 service returned unknown XML for CompleteMultipartUpload REST API. " - + bodyContent); - } + if (Xml.validate(ErrorResponse.class, bodyContent)) { + ErrorResponse errorResponse = Xml.unmarshal(ErrorResponse.class, bodyContent); + throw new CompletionException( + new ErrorResponseException(errorResponse, response, null)); } + } catch (XmlParserException e) { + // As it is not message, fallback to parse CompleteMultipartUploadOutput + // XML. + } + try { + CompleteMultipartUploadResult result = + Xml.unmarshal(CompleteMultipartUploadResult.class, bodyContent); return new ObjectWriteResponse( response.headers(), - args.bucket(), - args.location(), - args.object(), - null, - response.header("x-amz-version-id")); - } catch (IOException e) { - throw new CompletionException(new MinioException(e)); - } finally { - response.close(); + result.bucket(), + result.location(), + result.object(), + result.etag(), + response.header("x-amz-version-id"), + result); + } catch (XmlParserException e) { + // As this CompleteMultipartUpload REST call succeeded, just log it. + Logger.getLogger(BaseS3Client.class.getName()) + .warning( + "S3 service returned unknown XML for CompleteMultipartUpload REST API. " + + bodyContent); } - }); + } + + return new ObjectWriteResponse( + response.headers(), + args.bucket(), + args.location(), + args.object(), + null, + response.header("x-amz-version-id")); + } catch (IOException e) { + throw new CompletionException(new MinioException(e)); + } finally { + response.close(); + } + }); } private CompletableFuture completeMultipartUpload( CompleteMultipartUploadArgs args, Http.Body body, int attempt) { return completeMultipartUpload(args, body) - .handle( - (response, ex) -> { - if (ex == null) return CompletableFuture.completedFuture(response); - - ex = ex.getCause(); - if (attempt == Math.max(1, args.maxRetries()) - 1 - || !(ex instanceof ErrorResponseException) - || !RETRYABLE_ERRORS.contains( - ((ErrorResponseException) ex).errorResponse().code())) { - return Utils.failedFuture(ex); - } - - if (args.delayMs() > 0) { - long maxBackoffLimit = args.delayMs() * (1L << (attempt + 1)); - long jitteredDelay = ThreadLocalRandom.current().nextLong(0, maxBackoffLimit); - try { - Thread.sleep(jitteredDelay); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return Utils.failedFuture( - new IllegalStateException("Retry timeout interrupted", e)); - } - } - - return completeMultipartUpload(args, body, attempt + 1); - }) + .handle((response, ex) -> { + if (ex == null) return CompletableFuture.completedFuture(response); + + ex = ex.getCause(); + if (attempt == Math.max(1, args.maxRetries()) - 1 + || !(ex instanceof ErrorResponseException) + || !RETRYABLE_ERRORS.contains(((ErrorResponseException) ex).errorResponse().code())) { + return Utils.failedFuture(ex); + } + + if (args.delayMs() > 0) { + long maxBackoffLimit = args.delayMs() * (1L << (attempt + 1)); + long jitteredDelay = ThreadLocalRandom.current().nextLong(0, maxBackoffLimit); + try { + Thread.sleep(jitteredDelay); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return Utils.failedFuture( + new IllegalStateException("Retry timeout interrupted", e)); + } + } + + return completeMultipartUpload(args, body, attempt + 1); + }) .thenCompose(future -> future); } @@ -831,25 +819,24 @@ public CompletableFuture copyObject(CopyObjectArgs args) { } return executePutAsync(args, headers, null, null) - .thenApply( - response -> { - try { - CopyObjectResult result = - Xml.unmarshal(CopyObjectResult.class, response.body().charStream()); - return new ObjectWriteResponse( - response.headers(), - args.bucket(), - args.region(), - args.object(), - result.etag(), - response.header("x-amz-version-id"), - result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + CopyObjectResult result = + Xml.unmarshal(CopyObjectResult.class, response.body().charStream()); + return new ObjectWriteResponse( + response.headers(), + args.bucket(), + args.region(), + args.object(), + result.etag(), + response.header("x-amz-version-id"), + result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -901,15 +888,13 @@ public CompletableFuture createBucket(CreateBucketArgs args) { .args(args) .build(), locationConstraint) - .thenApply( - response -> { - try { - return new GenericResponse( - response.headers(), args.bucket(), args.location(), null); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return new GenericResponse(response.headers(), args.bucket(), args.location(), null); + } finally { + response.close(); + } + }); } /** @@ -924,20 +909,18 @@ public CompletableFuture createMultipartUpload( CreateMultipartUploadArgs args) { checkArgs(args); return executePostAsync(args, args.headers(), new Http.QueryParameters("uploads", ""), null) - .thenApply( - response -> { - try { - InitiateMultipartUploadResult result = - Xml.unmarshal( - InitiateMultipartUploadResult.class, response.body().charStream()); - return new CreateMultipartUploadResponse( - response.headers(), args.bucket(), args.location(), args.object(), result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + InitiateMultipartUploadResult result = + Xml.unmarshal(InitiateMultipartUploadResult.class, response.body().charStream()); + return new CreateMultipartUploadResponse( + response.headers(), args.bucket(), args.location(), args.object(), result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -963,33 +946,32 @@ public CompletableFuture deleteObjects(DeleteObjectsArgs : null, new Http.QueryParameters("delete", ""), body) - .thenApply( - response -> { - try { - String bodyContent = response.body().string(); - try { - if (Xml.validate(DeleteResult.Error.class, bodyContent)) { - DeleteResult.Error error = Xml.unmarshal(DeleteResult.Error.class, bodyContent); - DeleteResult result = new DeleteResult(error); - return new DeleteObjectsResponse( - response.headers(), args.bucket(), args.region(), result); - } - } catch (XmlParserException e) { - // Ignore this exception as it is not message, - // but parse it as message below. - } - - DeleteResult result = Xml.unmarshal(DeleteResult.class, bodyContent); + .thenApply(response -> { + try { + String bodyContent = response.body().string(); + try { + if (Xml.validate(DeleteResult.Error.class, bodyContent)) { + DeleteResult.Error error = Xml.unmarshal(DeleteResult.Error.class, bodyContent); + DeleteResult result = new DeleteResult(error); return new DeleteObjectsResponse( response.headers(), args.bucket(), args.region(), result); - } catch (IOException e) { - throw new CompletionException(new MinioException(e)); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); } - }); + } catch (XmlParserException e) { + // Ignore this exception as it is not message, + // but parse it as message below. + } + + DeleteResult result = Xml.unmarshal(DeleteResult.class, bodyContent); + return new DeleteObjectsResponse( + response.headers(), args.bucket(), args.region(), result); + } catch (IOException e) { + throw new CompletionException(new MinioException(e)); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1010,25 +992,24 @@ public CompletableFuture getBucketLocation(GetBucketLocationArgs args) { .queryParams(new Http.QueryParameters("location", null)) .build(), Http.US_EAST_1) - .thenApply( - response -> { - String location; - try (ResponseBody body = response.body()) { - LocationConstraint lc = Xml.unmarshal(LocationConstraint.class, body.charStream()); - if (lc.location() == null || lc.location().equals("")) { - location = Http.US_EAST_1; - } else if (lc.location().equals("EU") && this.baseUrl.awsDomainSuffix() != null) { - location = "eu-west-1"; // eu-west-1 is also referred as 'EU'. - } else { - location = lc.location(); - } - } catch (XmlParserException e) { - throw new CompletionException(e); - } - - regionCache.put(args.bucket(), location); - return location; - }); + .thenApply(response -> { + String location; + try (ResponseBody body = response.body()) { + LocationConstraint lc = Xml.unmarshal(LocationConstraint.class, body.charStream()); + if (lc.location() == null || lc.location().equals("")) { + location = Http.US_EAST_1; + } else if (lc.location().equals("EU") && this.baseUrl.awsDomainSuffix() != null) { + location = "eu-west-1"; // eu-west-1 is also referred as 'EU'. + } else { + location = lc.location(); + } + } catch (XmlParserException e) { + throw new CompletionException(e); + } + + regionCache.put(args.bucket(), location); + return location; + }); } /** @@ -1061,10 +1042,9 @@ public CompletableFuture headObject(HeadObjectArgs args) { (args.versionId() != null) ? new Http.QueryParameters("versionId", args.versionId()) : null) - .thenApply( - response -> - new HeadObjectResponse( - response.headers(), args.bucket(), args.region(), args.object())); + .thenApply(response -> + new HeadObjectResponse( + response.headers(), args.bucket(), args.region(), args.object())); } /** @@ -1087,18 +1067,17 @@ public CompletableFuture listBucketsAPI(ListBucketsArgs arg } return executeGetAsync(args, null, queryParams) - .thenApply( - response -> { - try { - ListAllMyBucketsResult result = - Xml.unmarshal(ListAllMyBucketsResult.class, response.body().charStream()); - return new ListBucketsResponse(response.headers(), result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + ListAllMyBucketsResult result = + Xml.unmarshal(ListAllMyBucketsResult.class, response.body().charStream()); + return new ListBucketsResponse(response.headers(), result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1127,19 +1106,18 @@ public CompletableFuture listMultipartUploads( if (args.uploadIdMarker() != null) queryParams.put("upload-id-marker", args.uploadIdMarker()); return executeGetAsync(args, null, queryParams) - .thenApply( - response -> { - try { - ListMultipartUploadsResult result = - Xml.unmarshal(ListMultipartUploadsResult.class, response.body().charStream()); - return new ListMultipartUploadsResponse( - response.headers(), args.bucket(), args.region(), result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + ListMultipartUploadsResult result = + Xml.unmarshal(ListMultipartUploadsResult.class, response.body().charStream()); + return new ListMultipartUploadsResponse( + response.headers(), args.bucket(), args.region(), result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } private Http.QueryParameters getCommonListObjectsQueryParams( @@ -1172,19 +1150,18 @@ public CompletableFuture listObjectsV1(ListObjectsV1Args if (args.marker() != null) queryParams.put("marker", args.marker()); return executeGetAsync(args, null, queryParams) - .thenApply( - response -> { - try { - ListBucketResultV1 result = - Xml.unmarshal(ListBucketResultV1.class, response.body().charStream()); - return new ListObjectsV1Response( - response.headers(), args.bucket(), args.region(), result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + ListBucketResultV1 result = + Xml.unmarshal(ListBucketResultV1.class, response.body().charStream()); + return new ListObjectsV1Response( + response.headers(), args.bucket(), args.region(), result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1208,19 +1185,18 @@ public CompletableFuture listObjectsV2(ListObjectsV2Args queryParams.put("list-type", "2"); return executeGetAsync(args, null, queryParams) - .thenApply( - response -> { - try { - ListBucketResultV2 result = - Xml.unmarshal(ListBucketResultV2.class, response.body().charStream()); - return new ListObjectsV2Response( - response.headers(), args.bucket(), args.region(), result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + ListBucketResultV2 result = + Xml.unmarshal(ListBucketResultV2.class, response.body().charStream()); + return new ListObjectsV2Response( + response.headers(), args.bucket(), args.region(), result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1245,19 +1221,18 @@ public CompletableFuture listObjectVersions( queryParams.put("versions", ""); return executeGetAsync(args, null, queryParams) - .thenApply( - response -> { - try { - ListVersionsResult result = - Xml.unmarshal(ListVersionsResult.class, response.body().charStream()); - return new ListObjectVersionsResponse( - response.headers(), args.bucket(), args.region(), result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + ListVersionsResult result = + Xml.unmarshal(ListVersionsResult.class, response.body().charStream()); + return new ListObjectVersionsResponse( + response.headers(), args.bucket(), args.region(), result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1279,19 +1254,18 @@ public CompletableFuture listParts(ListPartsArgs args) { } return executeGetAsync(args, null, queryParams) - .thenApply( - response -> { - try { - ListPartsResult result = - Xml.unmarshal(ListPartsResult.class, response.body().charStream()); - return new ListPartsResponse( - response.headers(), args.bucket(), args.region(), args.object(), result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + ListPartsResult result = + Xml.unmarshal(ListPartsResult.class, response.body().charStream()); + return new ListPartsResponse( + response.headers(), args.bucket(), args.region(), args.object(), result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } private Object[] createBody(PutObjectAPIBaseArgs args, MediaType contentType) @@ -1392,20 +1366,19 @@ public CompletableFuture putObject(PutObjectAPIArgs args) { Http.Body body = (Http.Body) result[0]; Http.Headers headers = (Http.Headers) result[1]; return executePutAsync(args, headers, null, body) - .thenApply( - response -> { - try { - return new ObjectWriteResponse( - response.headers(), - args.bucket(), - args.region(), - args.object(), - response.header("ETag").replaceAll("\"", ""), - response.header("x-amz-version-id")); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return new ObjectWriteResponse( + response.headers(), + args.bucket(), + args.region(), + args.object(), + response.header("ETag").replaceAll("\"", ""), + response.header("x-amz-version-id")); + } finally { + response.close(); + } + }); } /** @@ -1432,21 +1405,20 @@ public CompletableFuture uploadPart(UploadPartArgs args) { new Http.QueryParameters( "partNumber", Integer.toString(args.partNumber()), "uploadId", args.uploadId()), body) - .thenApply( - response -> { - try { - return new UploadPartResponse( - response.headers(), - args.bucket(), - args.region(), - args.object(), - args.uploadId(), - args.partNumber(), - response.header("ETag").replaceAll("\"", "")); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return new UploadPartResponse( + response.headers(), + args.bucket(), + args.region(), + args.object(), + args.uploadId(), + args.partNumber(), + response.header("ETag").replaceAll("\"", "")); + } finally { + response.close(); + } + }); } /** @@ -1465,24 +1437,23 @@ public CompletableFuture uploadPartCopy(UploadPartCopyAr new Http.QueryParameters( "partNumber", Integer.toString(args.partNumber()), "uploadId", args.uploadId()), null) - .thenApply( - response -> { - try { - CopyPartResult result = - Xml.unmarshal(CopyPartResult.class, response.body().charStream()); - return new UploadPartCopyResponse( - response.headers(), - args.bucket(), - args.region(), - args.object(), - args.uploadId(), - args.partNumber(), - result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + CopyPartResult result = + Xml.unmarshal(CopyPartResult.class, response.body().charStream()); + return new UploadPartCopyResponse( + response.headers(), + args.bucket(), + args.region(), + args.object(), + args.uploadId(), + args.partNumber(), + result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } } diff --git a/api/src/main/java/io/minio/GetObjectAttributesArgs.java b/api/src/main/java/io/minio/GetObjectAttributesArgs.java index da1d6a522..1c184d5b9 100644 --- a/api/src/main/java/io/minio/GetObjectAttributesArgs.java +++ b/api/src/main/java/io/minio/GetObjectAttributesArgs.java @@ -55,10 +55,9 @@ protected void validate(GetObjectAttributesArgs args) { } public Builder objectAttributes(String[] objectAttributes) { - operations.add( - args -> - args.objectAttributes = - objectAttributes == null ? null : Arrays.asList(objectAttributes)); + operations.add(args -> + args.objectAttributes = + objectAttributes == null ? null : Arrays.asList(objectAttributes)); return this; } diff --git a/api/src/main/java/io/minio/MinioAsyncClient.java b/api/src/main/java/io/minio/MinioAsyncClient.java index e5e95a0aa..17e7d4651 100644 --- a/api/src/main/java/io/minio/MinioAsyncClient.java +++ b/api/src/main/java/io/minio/MinioAsyncClient.java @@ -328,15 +328,14 @@ public CompletableFuture getObject(GetObjectArgs args) { (args.versionId() != null) ? new Http.QueryParameters("versionId", args.versionId()) : null) - .thenApply( - response -> { - return new GetObjectResponse( - response.headers(), - args.bucket(), - args.region(), - args.object(), - response.body().byteStream()); - }); + .thenApply(response -> { + return new GetObjectResponse( + response.headers(), + args.bucket(), + args.region(), + args.object(), + response.body().byteStream()); + }); } private void downloadObject( @@ -543,36 +542,34 @@ public CompletableFuture copyObject(CopyObjectArgs args) { ? headObject(new HeadObjectArgs(args.source())) : CompletableFuture.completedFuture((HeadObjectResponse) null); return future - .thenApply( - response -> - response == null - ? args - : new CopyObjectArgs( - args, new SourceObject(args.source(), response.size(), response.etag()))) - .thenCompose( - copyArgs -> { - long size = copyArgs.source().objectSize(); - if (size < ObjectWriteArgs.MAX_PART_SIZE - && copyArgs.source().offset() == null - && copyArgs.source().length() == null) { - return super.copyObject(copyArgs); - } + .thenApply(response -> + response == null + ? args + : new CopyObjectArgs( + args, new SourceObject(args.source(), response.size(), response.etag()))) + .thenCompose(copyArgs -> { + long size = copyArgs.source().objectSize(); + if (size < ObjectWriteArgs.MAX_PART_SIZE + && copyArgs.source().offset() == null + && copyArgs.source().length() == null) { + return super.copyObject(copyArgs); + } - if (size > ObjectWriteArgs.MAX_PART_SIZE) { - if (copyArgs.metadataDirective() == Directive.COPY) { - throw new IllegalArgumentException( - "COPY metadata directive is not applicable to source object size greater" - + " than 5 GiB"); - } - } - if (copyArgs.taggingDirective() == Directive.COPY) { - throw new IllegalArgumentException( - "COPY tagging directive is not applicable to source object size greater than" - + " 5 GiB"); - } + if (size > ObjectWriteArgs.MAX_PART_SIZE) { + if (copyArgs.metadataDirective() == Directive.COPY) { + throw new IllegalArgumentException( + "COPY metadata directive is not applicable to source object size greater" + + " than 5 GiB"); + } + } + if (copyArgs.taggingDirective() == Directive.COPY) { + throw new IllegalArgumentException( + "COPY tagging directive is not applicable to source object size greater than" + + " 5 GiB"); + } - return composeObject(new ComposeObjectArgs(copyArgs)); - }); + return composeObject(new ComposeObjectArgs(copyArgs)); + }); } /** Calculates part count for given list of {@link SourceObject}. */ @@ -761,26 +758,23 @@ private CompletableFuture composeObject( ComposeObjectArgs args, int partCount) { String[] uploadId = {null}; return createMultipartUpload(new CreateMultipartUploadArgs(args)) - .thenCompose( - response -> { - uploadId[0] = response.result().uploadId(); - return uploadParts(args, partCount, uploadId[0]); - }) - .thenCompose( - parts -> - completeMultipartUpload(new CompleteMultipartUploadArgs(args, uploadId[0], parts))) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (uploadId[0] != null) { - try { - abortMultipartUpload(new AbortMultipartUploadArgs(args, uploadId[0])).join(); - } catch (CompletionException ex) { - e.addSuppressed(ex.getCause()); - } - } - throw new CompletionException(e); - }); + .thenCompose(response -> { + uploadId[0] = response.result().uploadId(); + return uploadParts(args, partCount, uploadId[0]); + }) + .thenCompose(parts -> + completeMultipartUpload(new CompleteMultipartUploadArgs(args, uploadId[0], parts))) + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (uploadId[0] != null) { + try { + abortMultipartUpload(new AbortMultipartUploadArgs(args, uploadId[0])).join(); + } catch (CompletionException ex) { + e.addSuppressed(ex.getCause()); + } + } + throw new CompletionException(e); + }); } /** @@ -836,15 +830,14 @@ public CompletableFuture composeObject(ComposeObjectArgs ar args.validateSse(this.baseUrl.isHttps()); return calculatePartCount(args.sources()) - .thenCompose( - partCount -> { - if (partCount == 1 - && args.sources().get(0).offset() == null - && args.sources().get(0).length() == null) { - return copyObject(new CopyObjectArgs(args)); - } - return composeObject(args, partCount); - }); + .thenCompose(partCount -> { + if (partCount == 1 + && args.sources().get(0).offset() == null + && args.sources().get(0).length() == null) { + return copyObject(new CopyObjectArgs(args)); + } + return composeObject(args, partCount); + }); } /** @@ -1281,10 +1274,9 @@ public Iterable> listObjects(ListObjectsArgs args) { */ public CompletableFuture> listBuckets() { return listBucketsAPI(ListBucketsArgs.builder().build()) - .thenApply( - response -> { - return response.result().buckets(); - }); + .thenApply(response -> { + return response.result().buckets(); + }); } /** @@ -1418,24 +1410,22 @@ public void remove() { */ public CompletableFuture bucketExists(BucketExistsArgs args) { return executeHeadAsync(args, null, null) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e).errorResponse().code().equals(NO_SUCH_BUCKET)) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - try { - return response != null; - } finally { - if (response != null) response.close(); - } - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e).errorResponse().code().equals(NO_SUCH_BUCKET)) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + try { + return response != null; + } finally { + if (response != null) response.close(); + } + }); } /** @@ -1511,16 +1501,15 @@ public CompletableFuture getBucketVersioning( GetBucketVersioningArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("versioning", "")) - .thenApply( - response -> { - try { - return Xml.unmarshal(VersioningConfiguration.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return Xml.unmarshal(VersioningConfiguration.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1588,16 +1577,15 @@ public CompletableFuture getObjectLockConfiguration( GetObjectLockConfigurationArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("object-lock", "")) - .thenApply( - response -> { - try { - return Xml.unmarshal(ObjectLockConfiguration.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return Xml.unmarshal(ObjectLockConfiguration.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1658,30 +1646,28 @@ public CompletableFuture getObjectRetention(GetObjectRetentionArgs ar Http.QueryParameters queryParams = new Http.QueryParameters("retention", ""); if (args.versionId() != null) queryParams.put("versionId", args.versionId()); return executeGetAsync(args, null, queryParams) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals(NO_SUCH_OBJECT_LOCK_CONFIGURATION)) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - if (response == null) return null; - try { - return Xml.unmarshal(Retention.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e) + .errorResponse() + .code() + .equals(NO_SUCH_OBJECT_LOCK_CONFIGURATION)) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + if (response == null) return null; + try { + return Xml.unmarshal(Retention.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1761,31 +1747,29 @@ public CompletableFuture isObjectLegalHoldEnabled(IsObjectLegalHoldEnab Http.QueryParameters queryParams = new Http.QueryParameters("legal-hold", ""); if (args.versionId() != null) queryParams.put("versionId", args.versionId()); return executeGetAsync(args, null, queryParams) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals(NO_SUCH_OBJECT_LOCK_CONFIGURATION)) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - if (response == null) return false; - try { - LegalHold result = Xml.unmarshal(LegalHold.class, response.body().charStream()); - return result.status(); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e) + .errorResponse() + .code() + .equals(NO_SUCH_OBJECT_LOCK_CONFIGURATION)) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + if (response == null) return false; + try { + LegalHold result = Xml.unmarshal(LegalHold.class, response.body().charStream()); + return result.status(); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -1814,38 +1798,35 @@ private CompletableFuture> uploadPartsSequentially( ByteBuffer buffer, long partSize, List responses) { - return supplyAsync( - () -> - new UploadPartArgs( - args, - uploadId, - partReader.partNumber(), - buffer, - Checksum.makeHeaders( - partReader.hashers(), addContentSha256, addSha256Checksum))) + return supplyAsync(() -> + new UploadPartArgs( + args, + uploadId, + partReader.partNumber(), + buffer, + Checksum.makeHeaders(partReader.hashers(), addContentSha256, addSha256Checksum))) .thenCompose(partArgs -> uploadPart(partArgs)) - .thenCompose( - response -> { - responses.add(response); - try { - buffer.reset(); - if (partReader.partNumber() == partReader.partCount()) { - return CompletableFuture.completedFuture(responses); - } - partReader.read(buffer); - } catch (MinioException e) { - return Utils.failedFuture(e); - } - return uploadPartsSequentially( - args, - uploadId, - partReader, - addContentSha256, - addSha256Checksum, - buffer, - partSize, - responses); - }); + .thenCompose(response -> { + responses.add(response); + try { + buffer.reset(); + if (partReader.partNumber() == partReader.partCount()) { + return CompletableFuture.completedFuture(responses); + } + partReader.read(buffer); + } catch (MinioException e) { + return Utils.failedFuture(e); + } + return uploadPartsSequentially( + args, + uploadId, + partReader, + addContentSha256, + addSha256Checksum, + buffer, + partSize, + responses); + }); } private CompletableFuture> uploadPartsParallelly( @@ -1865,101 +1846,99 @@ private CompletableFuture> uploadPartsParallelly( AtomicBoolean errorOccurred = new AtomicBoolean(false); ConcurrentLinkedQueue exceptions = new ConcurrentLinkedQueue<>(); - return supplyAsync( - () -> { - try { - // Start uploader workers - for (int i = 0; i < parallelUploads; i++) { - Future result = - uploadExecutor.submit( - () -> { - try { - while (!errorOccurred.get()) { - UploadPartArgs.Wrapper part = queue.take(); - if (part.args() == null) break; // poison pill - try { - UploadPartResponse response = uploadPart(part.args()).join(); - uploadResults.add(response); - } finally { - // Always return the buffer to the pool, even on upload failure. - bufferPool.put(part.args().buffer()); - } - } - } catch (Throwable t) { - // Catch Throwable, not RuntimeException: an Error would otherwise escape - // into the discarded Future while the finally below still counts down - // doneLatch, leaving errorOccurred false and exceptions empty. The upload - // would then complete with a short part list and silently assemble a - // truncated object. uploadPart().join() failures surface here as - // CompletionException. The recorded throwable is rethrown to the caller - // below, so nothing is swallowed. - if (t instanceof InterruptedException) Thread.currentThread().interrupt(); - errorOccurred.set(true); // signal to all threads and the reader - exceptions.add(t); - } finally { - doneLatch.countDown(); - } - }); - if (result == null) { - throw new IllegalStateException( - "uploadExecutor.submit() returns null; this should not happen"); - } - } + return supplyAsync(() -> { + try { + // Start uploader workers + for (int i = 0; i < parallelUploads; i++) { + Future result = + uploadExecutor.submit(() -> { + try { + while (!errorOccurred.get()) { + UploadPartArgs.Wrapper part = queue.take(); + if (part.args() == null) break; // poison pill + try { + UploadPartResponse response = uploadPart(part.args()).join(); + uploadResults.add(response); + } finally { + // Always return the buffer to the pool, even on upload failure. + bufferPool.put(part.args().buffer()); + } + } + } catch (Throwable t) { + // Catch Throwable, not RuntimeException: an Error would otherwise escape + // into the discarded Future while the finally below still counts down + // doneLatch, leaving errorOccurred false and exceptions empty. The upload + // would then complete with a short part list and silently assemble a + // truncated object. uploadPart().join() failures surface here as + // CompletionException. The recorded throwable is rethrown to the caller + // below, so nothing is swallowed. + if (t instanceof InterruptedException) Thread.currentThread().interrupt(); + errorOccurred.set(true); // signal to all threads and the reader + exceptions.add(t); + } finally { + doneLatch.countDown(); + } + }); + if (result == null) { + throw new IllegalStateException( + "uploadExecutor.submit() returns null; this should not happen"); + } + } - // Reader: submit initial buffer - offerUntilDoneOrError( - queue, - errorOccurred, - new UploadPartArgs.Wrapper( - new UploadPartArgs( - args, - uploadId, - partReader.partNumber(), - buffer, - Checksum.makeHeaders( - partReader.hashers(), addContentSha256, addSha256Checksum)))); - - // Reader: loop to submit remaining parts - while (partReader.partNumber() != partReader.partCount() && !errorOccurred.get()) { - ByteBuffer buf = bufferPool.take(); - partReader.read(buf); - offerUntilDoneOrError( - queue, - errorOccurred, - new UploadPartArgs.Wrapper( - new UploadPartArgs( - args, - uploadId, - partReader.partNumber(), - buf, - Checksum.makeHeaders( - partReader.hashers(), addContentSha256, addSha256Checksum)))); - } + // Reader: submit initial buffer + offerUntilDoneOrError( + queue, + errorOccurred, + new UploadPartArgs.Wrapper( + new UploadPartArgs( + args, + uploadId, + partReader.partNumber(), + buffer, + Checksum.makeHeaders( + partReader.hashers(), addContentSha256, addSha256Checksum)))); + + // Reader: loop to submit remaining parts + while (partReader.partNumber() != partReader.partCount() && !errorOccurred.get()) { + ByteBuffer buf = bufferPool.take(); + partReader.read(buf); + offerUntilDoneOrError( + queue, + errorOccurred, + new UploadPartArgs.Wrapper( + new UploadPartArgs( + args, + uploadId, + partReader.partNumber(), + buf, + Checksum.makeHeaders( + partReader.hashers(), addContentSha256, addSha256Checksum)))); + } - // Signal all workers to stop with poison pills - for (int i = 0; i < parallelUploads; i++) { - offerUntilDoneOrError(queue, errorOccurred, new UploadPartArgs.Wrapper(null)); - } + // Signal all workers to stop with poison pills + for (int i = 0; i < parallelUploads; i++) { + offerUntilDoneOrError(queue, errorOccurred, new UploadPartArgs.Wrapper(null)); + } - doneLatch.await(); - uploadExecutor.shutdown(); + doneLatch.await(); + uploadExecutor.shutdown(); - if (!exceptions.isEmpty()) { - CompletionException combined = - new CompletionException("uploadPartsParallelly failed", exceptions.peek()); - exceptions.stream().skip(1).forEach(combined::addSuppressed); - throw combined; - } + if (!exceptions.isEmpty()) { + CompletionException combined = + new CompletionException("uploadPartsParallelly failed", exceptions.peek()); + exceptions.stream().skip(1).forEach(combined::addSuppressed); + throw combined; + } - uploadResults.sort(Comparator.comparingInt(r -> r.part().partNumber())); - return uploadResults; + uploadResults.sort(Comparator.comparingInt(r -> r.part().partNumber())); + return uploadResults; - } catch (InterruptedException | MinioException e) { - throw new CompletionException(e); - } finally { - uploadExecutor.shutdownNow(); // ensure executor exits on error - } - }); + } catch (InterruptedException | MinioException e) { + throw new CompletionException(e); + } finally { + uploadExecutor.shutdownNow(); // ensure executor exits on error + } + }); } /** @@ -2091,54 +2070,51 @@ private CompletableFuture putObject( final ByteBuffer finalBuffer = buffer; final int finalParallelUploads = parallelUploads; return createMultipartUpload(new CreateMultipartUploadArgs(args, contentType, algorithm)) - .thenCompose( - response -> { - uploadId[0] = response.result().uploadId(); - // Do sequential multipart uploads - if (finalParallelUploads == 1) { - return uploadPartsSequentially( + .thenCompose(response -> { + uploadId[0] = response.result().uploadId(); + // Do sequential multipart uploads + if (finalParallelUploads == 1) { + return uploadPartsSequentially( + args, + uploadId[0], + finalPartReader, + addContentSha256, + addSha256Checksum, + finalBuffer, + args.partSize(), + new ArrayList()); + } + + // Do sequential multipart uploads + return uploadPartsParallelly( + args, + uploadId[0], + finalPartReader, + addContentSha256, + addSha256Checksum, + finalBuffer, + args.partSize(), + finalParallelUploads); + }) + .thenCompose(responses -> + completeMultipartUpload( + new CompleteMultipartUploadArgs( args, uploadId[0], - finalPartReader, - addContentSha256, - addSha256Checksum, - finalBuffer, - args.partSize(), - new ArrayList()); - } - - // Do sequential multipart uploads - return uploadPartsParallelly( - args, - uploadId[0], - finalPartReader, - addContentSha256, - addSha256Checksum, - finalBuffer, - args.partSize(), - finalParallelUploads); - }) - .thenCompose( - responses -> - completeMultipartUpload( - new CompleteMultipartUploadArgs( - args, - uploadId[0], - responses.stream() - .map(UploadPartResponse::part) - .toArray(io.minio.messages.Part[]::new)))) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (uploadId[0] != null) { - try { - abortMultipartUpload(new AbortMultipartUploadArgs(args, uploadId[0])).join(); - } catch (CompletionException ex) { - e.addSuppressed(ex.getCause()); - } - } - throw new CompletionException(e); - }); + responses.stream() + .map(UploadPartResponse::part) + .toArray(io.minio.messages.Part[]::new)))) + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (uploadId[0] != null) { + try { + abortMultipartUpload(new AbortMultipartUploadArgs(args, uploadId[0])).join(); + } catch (CompletionException ex) { + e.addSuppressed(ex.getCause()); + } + } + throw new CompletionException(e); + }); } /** @@ -2230,25 +2206,23 @@ public CompletableFuture uploadObject(UploadObjectArgs args try { final RandomAccessFile file = new RandomAccessFile(args.filename(), "r"); return putObject(args, file, args.contentType(), !this.baseUrl.isHttps()) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - try { - file.close(); - } catch (IOException ex) { - e.addSuppressed(new MinioException(ex)); - } - throw new CompletionException(e); - }) - .thenApply( - objectWriteResponse -> { - try { - file.close(); - } catch (IOException e) { - throw new CompletionException(new MinioException(e)); - } - return objectWriteResponse; - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + try { + file.close(); + } catch (IOException ex) { + e.addSuppressed(new MinioException(ex)); + } + throw new CompletionException(e); + }) + .thenApply(objectWriteResponse -> { + try { + file.close(); + } catch (IOException e) { + throw new CompletionException(new MinioException(e)); + } + return objectWriteResponse; + }); } catch (IOException e) { return Utils.failedFuture(new MinioException(e)); } @@ -2269,55 +2243,49 @@ public CompletableFuture uploadObject(UploadObjectArgs args public CompletableFuture getBucketPolicy(GetBucketPolicyArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("policy", "")) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals(NO_SUCH_BUCKET_POLICY)) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - if (response == null) return ""; - try { - byte[] buf = new byte[MAX_BUCKET_POLICY_SIZE]; - int bytesRead = 0; - bytesRead = response.body().byteStream().read(buf, 0, MAX_BUCKET_POLICY_SIZE); - if (bytesRead < 0) { - throw new CompletionException( - new IOException("unexpected EOF when reading bucket policy")); - } - - // Read one byte extra to ensure only MAX_BUCKET_POLICY_SIZE data is sent by the - // server. - if (bytesRead == MAX_BUCKET_POLICY_SIZE) { - int byteRead = 0; - while (byteRead == 0) { - byteRead = response.body().byteStream().read(); - if (byteRead < 0) { - break; // reached EOF which is fine. - } + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e).errorResponse().code().equals(NO_SUCH_BUCKET_POLICY)) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + if (response == null) return ""; + try { + byte[] buf = new byte[MAX_BUCKET_POLICY_SIZE]; + int bytesRead = 0; + bytesRead = response.body().byteStream().read(buf, 0, MAX_BUCKET_POLICY_SIZE); + if (bytesRead < 0) { + throw new CompletionException( + new IOException("unexpected EOF when reading bucket policy")); + } - if (byteRead > 0) { - throw new CompletionException( - new BucketPolicyTooLargeException(args.bucket())); - } - } + // Read one byte extra to ensure only MAX_BUCKET_POLICY_SIZE data is sent by the + // server. + if (bytesRead == MAX_BUCKET_POLICY_SIZE) { + int byteRead = 0; + while (byteRead == 0) { + byteRead = response.body().byteStream().read(); + if (byteRead < 0) { + break; // reached EOF which is fine. } - return new String(buf, 0, bytesRead, StandardCharsets.UTF_8); - } catch (IOException e) { - throw new CompletionException(new MinioException(e)); - } finally { - response.close(); + if (byteRead > 0) { + throw new CompletionException(new BucketPolicyTooLargeException(args.bucket())); + } } - }); + } + + return new String(buf, 0, bytesRead, StandardCharsets.UTF_8); + } catch (IOException e) { + throw new CompletionException(new MinioException(e)); + } finally { + response.close(); + } + }); } /** @@ -2380,23 +2348,18 @@ public CompletableFuture setBucketPolicy(SetBucketPolicyArgs args) { public CompletableFuture deleteBucketPolicy(DeleteBucketPolicyArgs args) { checkArgs(args); return executeDeleteAsync(args, null, new Http.QueryParameters("policy", "")) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals(NO_SUCH_BUCKET_POLICY)) { - return null; - } - } - throw new CompletionException(e); - }) - .thenAccept( - response -> { - if (response != null) response.close(); - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e).errorResponse().code().equals(NO_SUCH_BUCKET_POLICY)) { + return null; + } + } + throw new CompletionException(e); + }) + .thenAccept(response -> { + if (response != null) response.close(); + }); } /** @@ -2467,30 +2430,28 @@ public CompletableFuture deleteBucketLifecycle(DeleteBucketLifecycleArgs a public CompletableFuture getBucketLifecycle(GetBucketLifecycleArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("lifecycle", "")) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals("NoSuchLifecycleConfiguration")) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - if (response == null) return null; - try { - return Xml.unmarshal(LifecycleConfiguration.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e) + .errorResponse() + .code() + .equals("NoSuchLifecycleConfiguration")) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + if (response == null) return null; + try { + return Xml.unmarshal(LifecycleConfiguration.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -2509,16 +2470,15 @@ public CompletableFuture getBucketNotification( GetBucketNotificationArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("notification", "")) - .thenApply( - response -> { - try { - return Xml.unmarshal(NotificationConfiguration.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return Xml.unmarshal(NotificationConfiguration.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -2599,30 +2559,28 @@ public CompletableFuture getBucketReplication( GetBucketReplicationArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("replication", "")) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals("ReplicationConfigurationNotFoundError")) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - if (response == null) return null; - try { - return Xml.unmarshal(ReplicationConfiguration.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e) + .errorResponse() + .code() + .equals("ReplicationConfigurationNotFoundError")) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + if (response == null) return null; + try { + return Xml.unmarshal(ReplicationConfiguration.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -2849,30 +2807,28 @@ public CompletableFuture setBucketEncryption(SetBucketEncryptionArgs args) public CompletableFuture getBucketEncryption(GetBucketEncryptionArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("encryption", "")) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals(SERVER_SIDE_ENCRYPTION_CONFIGURATION_NOT_FOUND_ERROR)) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - if (response == null) return new SseConfiguration(null); - try { - return Xml.unmarshal(SseConfiguration.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e) + .errorResponse() + .code() + .equals(SERVER_SIDE_ENCRYPTION_CONFIGURATION_NOT_FOUND_ERROR)) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + if (response == null) return new SseConfiguration(null); + try { + return Xml.unmarshal(SseConfiguration.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -2889,23 +2845,21 @@ public CompletableFuture getBucketEncryption(GetBucketEncrypti public CompletableFuture deleteBucketEncryption(DeleteBucketEncryptionArgs args) { checkArgs(args); return executeDeleteAsync(args, null, new Http.QueryParameters("encryption", "")) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals(SERVER_SIDE_ENCRYPTION_CONFIGURATION_NOT_FOUND_ERROR)) { - return null; - } - } - throw new CompletionException(e); - }) - .thenAccept( - response -> { - if (response != null) response.close(); - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e) + .errorResponse() + .code() + .equals(SERVER_SIDE_ENCRYPTION_CONFIGURATION_NOT_FOUND_ERROR)) { + return null; + } + } + throw new CompletionException(e); + }) + .thenAccept(response -> { + if (response != null) response.close(); + }); } /** @@ -2922,27 +2876,25 @@ public CompletableFuture deleteBucketEncryption(DeleteBucketEncryptionArgs public CompletableFuture getBucketTags(GetBucketTagsArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("tagging", "")) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e).errorResponse().code().equals("NoSuchTagSet")) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - if (response == null) return new Tags(); - try { - return Xml.unmarshal(Tags.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e).errorResponse().code().equals("NoSuchTagSet")) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + if (response == null) return new Tags(); + try { + return Xml.unmarshal(Tags.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -3005,16 +2957,15 @@ public CompletableFuture getObjectTags(GetObjectTagsArgs args) { Http.QueryParameters queryParams = new Http.QueryParameters("tagging", ""); if (args.versionId() != null) queryParams.put("versionId", args.versionId()); return executeGetAsync(args, null, queryParams) - .thenApply( - response -> { - try { - return Xml.unmarshal(Tags.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return Xml.unmarshal(Tags.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -3080,30 +3031,28 @@ public CompletableFuture deleteObjectTags(DeleteObjectTagsArgs args) { public CompletableFuture getBucketCors(GetBucketCorsArgs args) { checkArgs(args); return executeGetAsync(args, null, new Http.QueryParameters("cors", "")) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - if (e instanceof ErrorResponseException) { - if (((ErrorResponseException) e) - .errorResponse() - .code() - .equals("NoSuchCORSConfiguration")) { - return null; - } - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - if (response == null) return new CORSConfiguration(null); - try { - return Xml.unmarshal(CORSConfiguration.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + if (e instanceof ErrorResponseException) { + if (((ErrorResponseException) e) + .errorResponse() + .code() + .equals("NoSuchCORSConfiguration")) { + return null; + } + } + throw new CompletionException(e); + }) + .thenApply(response -> { + if (response == null) return new CORSConfiguration(null); + try { + return Xml.unmarshal(CORSConfiguration.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -3186,16 +3135,15 @@ public CompletableFuture getObjectAcl(GetObjectAclArgs args Http.QueryParameters queryParams = new Http.QueryParameters("acl", ""); if (args.versionId() != null) queryParams.put("versionId", args.versionId()); return executeGetAsync(args, null, queryParams) - .thenApply( - response -> { - try { - return Xml.unmarshal(AccessControlPolicy.class, response.body().charStream()); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + return Xml.unmarshal(AccessControlPolicy.class, response.body().charStream()); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -3234,28 +3182,27 @@ public CompletableFuture getObjectAttributes( } return executeGetAsync(args, headers, queryParams) - .thenApply( - response -> { - try { - GetObjectAttributesOutput result = - Xml.unmarshal(GetObjectAttributesOutput.class, response.body().charStream()); - - String value = response.headers().get("x-amz-delete-marker"); - if (value != null) result.setDeleteMarker(Boolean.valueOf(value)); - value = response.headers().get("Last-Modified"); - if (value != null) { - result.setLastModified(ZonedDateTime.parse(value, Time.HTTP_HEADER_DATE_FORMAT)); - } - result.setVersionId(response.headers().get("x-amz-version-id")); + .thenApply(response -> { + try { + GetObjectAttributesOutput result = + Xml.unmarshal(GetObjectAttributesOutput.class, response.body().charStream()); + + String value = response.headers().get("x-amz-delete-marker"); + if (value != null) result.setDeleteMarker(Boolean.valueOf(value)); + value = response.headers().get("Last-Modified"); + if (value != null) { + result.setLastModified(ZonedDateTime.parse(value, Time.HTTP_HEADER_DATE_FORMAT)); + } + result.setVersionId(response.headers().get("x-amz-version-id")); - return new GetObjectAttributesResponse( - response.headers(), args.bucket(), args.region(), args.object(), result); - } catch (XmlParserException e) { - throw new CompletionException(e); - } finally { - response.close(); - } - }); + return new GetObjectAttributesResponse( + response.headers(), args.bucket(), args.region(), args.object(), result); + } catch (XmlParserException e) { + throw new CompletionException(e); + } finally { + response.close(); + } + }); } /** @@ -3350,48 +3297,45 @@ public CompletableFuture uploadSnowballObjects( } return baos; }) - .thenCompose( - baos -> { - Http.Headers headers = args.makeHeaders(); - headers.put("X-Amz-Meta-Snowball-Auto-Extract", "true"); - - if (args.stagingFilename() == null) { - byte[] data = baos.toByteArray(); - return putObject(new PutObjectAPIArgs(args, data, data.length, headers)); - } + .thenCompose(baos -> { + Http.Headers headers = args.makeHeaders(); + headers.put("X-Amz-Meta-Snowball-Auto-Extract", "true"); - long length = Paths.get(args.stagingFilename()).toFile().length(); - if (length > ObjectWriteArgs.MAX_OBJECT_SIZE) { - throw new IllegalArgumentException( - "tarball size " + length + " is more than maximum allowed 5TiB"); - } - final RandomAccessFile file; - try { - file = new RandomAccessFile(args.stagingFilename(), "r"); - } catch (IOException e) { - throw new CompletionException(new MinioException(e)); - } - return putObject(new PutObjectAPIArgs(args, file, length, headers)) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - try { - file.close(); - } catch (IOException ex) { - e.addSuppressed(new MinioException(ex)); - } - throw new CompletionException(e); - }) - .thenApply( - response -> { - try { - file.close(); - } catch (IOException e) { - throw new CompletionException(new MinioException(e)); - } - return response; - }); - }); + if (args.stagingFilename() == null) { + byte[] data = baos.toByteArray(); + return putObject(new PutObjectAPIArgs(args, data, data.length, headers)); + } + + long length = Paths.get(args.stagingFilename()).toFile().length(); + if (length > ObjectWriteArgs.MAX_OBJECT_SIZE) { + throw new IllegalArgumentException( + "tarball size " + length + " is more than maximum allowed 5TiB"); + } + final RandomAccessFile file; + try { + file = new RandomAccessFile(args.stagingFilename(), "r"); + } catch (IOException e) { + throw new CompletionException(new MinioException(e)); + } + return putObject(new PutObjectAPIArgs(args, file, length, headers)) + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + try { + file.close(); + } catch (IOException ex) { + e.addSuppressed(new MinioException(ex)); + } + throw new CompletionException(e); + }) + .thenApply(response -> { + try { + file.close(); + } catch (IOException e) { + throw new CompletionException(new MinioException(e)); + } + return response; + }); + }); } /** @@ -3487,24 +3431,23 @@ public CompletableFuture putObjectFanOut(PutObjectFanOu } }) .thenCompose(body -> executePostAsync(args, null, null, new Http.Body(body))) - .thenApply( - response -> { - try { - JsonFactory jsonFactory = new JsonFactory(); - Iterator iterator = - OBJECT_MAPPER.readValues( - jsonFactory.createParser(response.body().byteStream()), - PutObjectFanOutResponse.Result.class); - List results = new ArrayList<>(); - iterator.forEachRemaining(results::add); - return new PutObjectFanOutResponse( - response.headers(), args.bucket(), args.region(), results); - } catch (IOException e) { - throw new CompletionException(new MinioException(e)); - } finally { - response.close(); - } - }); + .thenApply(response -> { + try { + JsonFactory jsonFactory = new JsonFactory(); + Iterator iterator = + OBJECT_MAPPER.readValues( + jsonFactory.createParser(response.body().byteStream()), + PutObjectFanOutResponse.Result.class); + List results = new ArrayList<>(); + iterator.forEachRemaining(results::add); + return new PutObjectFanOutResponse( + response.headers(), args.bucket(), args.region(), results); + } catch (IOException e) { + throw new CompletionException(new MinioException(e)); + } finally { + response.close(); + } + }); } /** @@ -3530,15 +3473,14 @@ public CompletableFuture promptObject(PromptObjectArgs arg byte[] data = OBJECT_MAPPER.writeValueAsString(promptArgs).getBytes(StandardCharsets.UTF_8); return executePostAsync( args, headers, queryParams, new Http.Body(data, data.length, null, null, null)) - .thenApply( - response -> { - return new PromptObjectResponse( - response.headers(), - args.bucket(), - args.region(), - args.object(), - response.body().byteStream()); - }); + .thenApply(response -> { + return new PromptObjectResponse( + response.headers(), + args.bucket(), + args.region(), + args.object(), + response.body().byteStream()); + }); } catch (JsonProcessingException e) { return Utils.failedFuture(new MinioException(e)); } @@ -3573,31 +3515,30 @@ private CompletableFuture appendObject( Checksum.makeHeaders(partReader.hashers(), addContentSha256, addSha256Checksum)); } return putObject(new PutObjectAPIArgs(args, buffer, headers)) - .thenCompose( - response -> { - long finalWriteOffset = writeOffset + buffer.length(); - try { - buffer.reset(); - if (partReader.partNumber() == partReader.partCount()) { - return CompletableFuture.completedFuture(response); - } - partReader.read(buffer); - } catch (MinioException e) { - return Utils.failedFuture(e); - } - return appendObject( - args, - finalWriteOffset, - partReader, - buffer, - null, - null, - null, - null, - null, - addContentSha256, - addSha256Checksum); - }); + .thenCompose(response -> { + long finalWriteOffset = writeOffset + buffer.length(); + try { + buffer.reset(); + if (partReader.partNumber() == partReader.partCount()) { + return CompletableFuture.completedFuture(response); + } + partReader.read(buffer); + } catch (MinioException e) { + return Utils.failedFuture(e); + } + return appendObject( + args, + finalWriteOffset, + partReader, + buffer, + null, + null, + null, + null, + null, + addContentSha256, + addSha256Checksum); + }); } long size = Math.min(length, partSize); @@ -3620,26 +3561,25 @@ private CompletableFuture appendObject( } return putObject(new PutObjectAPIArgs(args, file, size, headers)) - .thenCompose( - response -> { - long finalWriteOffset = writeOffset + size; - long finalLength = length - size; - if (finalLength == 0) { - return CompletableFuture.completedFuture(response); - } - return appendObject( - args, - finalWriteOffset, - null, - null, - null, - finalLength, - file, - partSize, - hashers, - addContentSha256, - addSha256Checksum); - }); + .thenCompose(response -> { + long finalWriteOffset = writeOffset + size; + long finalLength = length - size; + if (finalLength == 0) { + return CompletableFuture.completedFuture(response); + } + return appendObject( + args, + finalWriteOffset, + null, + null, + null, + finalLength, + file, + partSize, + hashers, + addContentSha256, + addSha256Checksum); + }); } /** @@ -3651,126 +3591,121 @@ private CompletableFuture appendObject( public CompletableFuture appendObject(AppendObjectArgs args) { checkArgs(args); return headObject(new HeadObjectArgs(args)) - .thenCompose( - response -> { - Checksum.Algorithm algorithm = null; - if (response.checksumType() != null) { - if (response.checksumType() != Checksum.Type.FULL_OBJECT) { - return Utils.failedFuture( - new MinioException( - "append object does not support checksum type " - + response.checksumType())); - } - Map checksums = response.checksums(); - if (checksums != null && !checksums.isEmpty()) { - algorithm = checksums.keySet().iterator().next(); - } - } + .thenCompose(response -> { + Checksum.Algorithm algorithm = null; + if (response.checksumType() != null) { + if (response.checksumType() != Checksum.Type.FULL_OBJECT) { + return Utils.failedFuture( + new MinioException( + "append object does not support checksum type " + response.checksumType())); + } + Map checksums = response.checksums(); + if (checksums != null && !checksums.isEmpty()) { + algorithm = checksums.keySet().iterator().next(); + } + } - long writeOffset = response.size(); - - long partSize = - args.chunkSize() != null ? args.chunkSize() : ObjectWriteArgs.MIN_MULTIPART_SIZE; - - boolean addContentSha256 = !this.baseUrl.isHttps(); - boolean addSha256Checksum = algorithm == Checksum.Algorithm.SHA256; - Checksum.Algorithm[] algorithms; - if (addContentSha256 && !addSha256Checksum) { - algorithms = - (algorithm != null) - ? new Checksum.Algorithm[] {algorithm, Checksum.Algorithm.SHA256} - : new Checksum.Algorithm[] {Checksum.Algorithm.SHA256}; - } else { - algorithms = - (algorithm != null) - ? new Checksum.Algorithm[] {algorithm} - : new Checksum.Algorithm[0]; - } + long writeOffset = response.size(); + + long partSize = + args.chunkSize() != null ? args.chunkSize() : ObjectWriteArgs.MIN_MULTIPART_SIZE; + + boolean addContentSha256 = !this.baseUrl.isHttps(); + boolean addSha256Checksum = algorithm == Checksum.Algorithm.SHA256; + Checksum.Algorithm[] algorithms; + if (addContentSha256 && !addSha256Checksum) { + algorithms = + (algorithm != null) + ? new Checksum.Algorithm[] {algorithm, Checksum.Algorithm.SHA256} + : new Checksum.Algorithm[] {Checksum.Algorithm.SHA256}; + } else { + algorithms = + (algorithm != null) + ? new Checksum.Algorithm[] {algorithm} + : new Checksum.Algorithm[0]; + } - if (args.stream() != null) { - try { - int partCount = - args.length() == null - ? -1 - : (int) Math.max((args.length() + partSize - 1) / partSize, 1); - PartReader partReader = - new PartReader(args.stream(), args.length(), partSize, partCount, algorithms); - ByteBuffer buffer = - new ByteBuffer(partReader.partCount() == 1 ? args.length() : partSize); - partReader.read(buffer); - return appendObject( - args, - writeOffset, - partReader, - buffer, - null, - null, - null, - null, - null, - addContentSha256, - addSha256Checksum); - } catch (MinioException e) { - return Utils.failedFuture(e); - } - } + if (args.stream() != null) { + try { + int partCount = + args.length() == null + ? -1 + : (int) Math.max((args.length() + partSize - 1) / partSize, 1); + PartReader partReader = + new PartReader(args.stream(), args.length(), partSize, partCount, algorithms); + ByteBuffer buffer = + new ByteBuffer(partReader.partCount() == 1 ? args.length() : partSize); + partReader.read(buffer); + return appendObject( + args, + writeOffset, + partReader, + buffer, + null, + null, + null, + null, + null, + addContentSha256, + addSha256Checksum); + } catch (MinioException e) { + return Utils.failedFuture(e); + } + } - try { - Map hashers = - Checksum.newHasherMap(algorithms); - if (args.data() != null) { - return appendObject( - args, - writeOffset, - null, - null, - args.data(), - args.length(), - null, - null, - hashers, - addContentSha256, - addSha256Checksum); - } + try { + Map hashers = Checksum.newHasherMap(algorithms); + if (args.data() != null) { + return appendObject( + args, + writeOffset, + null, + null, + args.data(), + args.length(), + null, + null, + hashers, + addContentSha256, + addSha256Checksum); + } - final RandomAccessFile file = new RandomAccessFile(args.filename(), "r"); - return appendObject( - args, - writeOffset, - null, - null, - null, - args.length(), - file, - partSize, - hashers, - addContentSha256, - addSha256Checksum) - .exceptionally( - e -> { - if (e instanceof CompletionException) e = e.getCause(); - try { - file.close(); - } catch (IOException ex) { - e.addSuppressed(new MinioException(ex)); - } - throw new CompletionException(e); - }) - .thenApply( - resp -> { - try { - file.close(); - } catch (IOException e) { - throw new CompletionException(new MinioException(e)); - } - return resp; - }); - } catch (MinioException e) { - return Utils.failedFuture(e); - } catch (IOException e) { - return Utils.failedFuture(new MinioException(e)); - } - }); + final RandomAccessFile file = new RandomAccessFile(args.filename(), "r"); + return appendObject( + args, + writeOffset, + null, + null, + null, + args.length(), + file, + partSize, + hashers, + addContentSha256, + addSha256Checksum) + .exceptionally(e -> { + if (e instanceof CompletionException) e = e.getCause(); + try { + file.close(); + } catch (IOException ex) { + e.addSuppressed(new MinioException(ex)); + } + throw new CompletionException(e); + }) + .thenApply(resp -> { + try { + file.close(); + } catch (IOException e) { + throw new CompletionException(new MinioException(e)); + } + return resp; + }); + } catch (MinioException e) { + return Utils.failedFuture(e); + } catch (IOException e) { + return Utils.failedFuture(new MinioException(e)); + } + }); } ///////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/api/src/main/java/io/minio/SelectResponseStream.java b/api/src/main/java/io/minio/SelectResponseStream.java index f46463aba..6e889d50a 100644 --- a/api/src/main/java/io/minio/SelectResponseStream.java +++ b/api/src/main/java/io/minio/SelectResponseStream.java @@ -168,7 +168,6 @@ public int read() throws IOException { if (payloadStream == null) { try { while (!this.populate()) {} - ; } catch (EOFException e) { return -1; } catch (MinioException e) { diff --git a/api/src/main/java/io/minio/Signer.java b/api/src/main/java/io/minio/Signer.java index c2ad64f95..bbd9d2272 100644 --- a/api/src/main/java/io/minio/Signer.java +++ b/api/src/main/java/io/minio/Signer.java @@ -143,10 +143,9 @@ private void setCanonicalHeaders(Set ignored_headers) { this.canonicalHeaders.put( signedHeader, headers.values(name).stream() - .map( - value -> { - return value.replaceAll("( +)", " ").trim(); - }) + .map(value -> { + return value.replaceAll("( +)", " ").trim(); + }) .collect(Collectors.joining(","))); } } diff --git a/api/src/test/java/io/minio/HttpExternalCertificatesTest.java b/api/src/test/java/io/minio/HttpExternalCertificatesTest.java index c7dbdeb00..4fd6abe3e 100644 --- a/api/src/test/java/io/minio/HttpExternalCertificatesTest.java +++ b/api/src/test/java/io/minio/HttpExternalCertificatesTest.java @@ -65,7 +65,7 @@ public static Collection bundles() { }); } - @Parameter() public String name; + @Parameter public String name; @Parameter(1) public String bundle; diff --git a/build.gradle b/build.gradle index 645a77338..6b27151bc 100644 --- a/build.gradle +++ b/build.gradle @@ -135,7 +135,7 @@ subprojects { target '**/*.java' importOrder 'edu', 'com', 'io', 'java', 'javax', 'org', '' removeUnusedImports() - googleJavaFormat('1.36.1') + googleJavaFormat('2.0.0') } groovyGradle { target '*.gradle' diff --git a/functional/TestMinioClient.java b/functional/TestMinioClient.java index 0b38a3000..e50327c78 100644 --- a/functional/TestMinioClient.java +++ b/functional/TestMinioClient.java @@ -1042,10 +1042,9 @@ public List createObjects(String bucketName, int count, int public void removeObjects(String bucketName, List results) throws Exception { List objects = results.stream() - .map( - result -> { - return new DeleteRequest.Object(result.object(), result.versionId()); - }) + .map(result -> { + return new DeleteRequest.Object(result.object(), result.versionId()); + }) .collect(Collectors.toList()); Exception ex = null; for (Result r :