public CompletableFuture getObject()

in src/main/java/s3NativeClient/com/amazonaws/s3/S3NativeClient.java [169:242]


    public CompletableFuture<GetObjectOutput> getObject(GetObjectRequest request,
            final ResponseDataConsumer<GetObjectOutput> dataHandler) {
        final CompletableFuture<GetObjectOutput> resultFuture = new CompletableFuture<>();
        final GetObjectOutput.Builder resultBuilder = GetObjectOutput.builder();
        final S3MetaRequestResponseHandler responseHandler = new S3MetaRequestResponseHandler() {
            private GetObjectOutput getObjectOutput;

            @Override
            public void onResponseHeaders(final int statusCode, final HttpHeader[] headers) {
                for (int headerIndex = 0; headerIndex < headers.length; ++headerIndex) {
                    try {
                        populateGetObjectOutputHeader(resultBuilder, headers[headerIndex]);
                    } catch (Exception e) {
                        resultFuture.completeExceptionally(new RuntimeException(
                                String.format(
                                        "Could not process response header {%s}: " + headers[headerIndex].getName()),
                                e));
                    }
                }

                populateGetObjectOutputUserMetadata(resultBuilder, headers);
                dataHandler.onResponseHeaders(statusCode, headers);
                getObjectOutput = resultBuilder.build();
                dataHandler.onResponse(getObjectOutput);
            }

            @Override
            public int onResponseBody(ByteBuffer bodyBytesIn, long objectRangeStart, long objectRangeEnd) {
                dataHandler.onResponseData(bodyBytesIn);
                return 0;
            }

            @Override
            public void onFinished(int errorCode, int responseStatus, byte[] errorPayload) {
                CrtS3RuntimeException ex = null;
                try {
                    if (errorCode != CRT.AWS_CRT_SUCCESS) {
                        ex = new CrtS3RuntimeException(errorCode, responseStatus, errorPayload);
                        dataHandler.onException(ex);
                    } else {
                        dataHandler.onFinished();
                    }
                } catch (Exception e) { /* ignore user callback exception */
                } finally {
                    if (ex != null) {
                        resultFuture.completeExceptionally(ex);
                    } else {
                        resultFuture.complete(getObjectOutput);
                    }
                }
            }
        };

        List<HttpHeader> headers = new LinkedList<>();

        // TODO: additional logic needed for *special* partitions
        headers.add(new HttpHeader("Host", request.bucket() + ".s3." + signingRegion + ".amazonaws.com"));
        populateGetObjectRequestHeaders(header -> headers.add(header), request);

        addCustomHeaders(headers, request.customHeaders());
        String getObjectRequestQueryParameters = getGetObjectRequestQueryParameters(request);
        String encodedPath = getEncodedPath(request.key(), getObjectRequestQueryParameters);

        HttpRequest httpRequest = new HttpRequest("GET", encodedPath, headers.toArray(new HttpHeader[0]), null);

        S3MetaRequestOptions metaRequestOptions = new S3MetaRequestOptions()
                .withMetaRequestType(S3MetaRequestOptions.MetaRequestType.GET_OBJECT).withHttpRequest(httpRequest)
                .withResponseHandler(responseHandler);

        try (final S3MetaRequest metaRequest = s3Client.makeMetaRequest(metaRequestOptions)) {
            addCancelCheckToFuture(resultFuture, metaRequest);
            return resultFuture;
        }
    }