use of software.amazon.awssdk.services.s3.model.GetObjectResponse in project aws-doc-sdk-examples by awsdocs.
the class S3Service method getObjectBytes.
public byte[] getObjectBytes(String bucketName, String keyName) {
S3Client s3 = getClient();
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(keyName).bucket(bucketName).build();
// Return the byte[] from this object.
ResponseBytes<GetObjectResponse> objectBytes = s3.getObjectAsBytes(objectRequest);
return objectBytes.asByteArray();
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.s3.model.GetObjectResponse in project aws-doc-sdk-examples by awsdocs.
the class GetObjectDataAsync method getObject.
public static void getObject(S3AsyncClient s3AsyncClient, String bucketName, String keyName, String path) {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(keyName).bucket(bucketName).build();
CompletableFuture<GetObjectResponse> futureGet = s3AsyncClient.getObject(objectRequest, AsyncResponseTransformer.toFile(Paths.get(path)));
futureGet.whenComplete((resp, err) -> {
try {
if (resp != null) {
System.out.println("Object downloaded. Details: " + resp);
} else {
err.printStackTrace();
}
} finally {
// Only close the client when you are completely done with it
s3AsyncClient.close();
}
});
futureGet.join();
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.model.GetObjectResponse in project aws-doc-sdk-examples by awsdocs.
the class S3Service method getObjectBytes.
public byte[] getObjectBytes(String bucketName, String keyName) {
try {
S3Client s3 = getClient();
GetObjectRequest objectRequest = GetObjectRequest.builder().key(keyName).bucket(bucketName).build();
ResponseBytes<GetObjectResponse> objectBytes = s3.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
return data;
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.s3.model.GetObjectResponse in project pravega by pravega.
the class S3ChunkStorage method doRead.
@Override
protected int doRead(ChunkHandle handle, long fromOffset, int length, byte[] buffer, int bufferOffset) throws ChunkStorageException {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(getObjectPath(handle.getChunkName())).range(getRangeWithLength(fromOffset, length)).bucket(config.getBucket()).build();
ResponseBytes<GetObjectResponse> objectBytes = client.getObjectAsBytes(objectRequest);
try (val inputStream = objectBytes.asInputStream()) {
return StreamHelpers.readAll(inputStream, buffer, bufferOffset, length);
}
} catch (Exception e) {
throw convertException(handle.getChunkName(), "doRead", e);
}
}
use of software.amazon.awssdk.services.s3.model.GetObjectResponse in project aws-doc-sdk-examples by awsdocs.
the class DetectPPE method getObjectBytes.
public static byte[] getObjectBytes(S3Client s3, String bucketName, String keyName) {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(keyName).bucket(bucketName).build();
ResponseBytes<GetObjectResponse> objectBytes = s3.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
return data;
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
Aggregations