use of software.amazon.awssdk.services.s3.model.GetObjectResponse in project aws-doc-sdk-examples by awsdocs.
the class DisplayFacesFrame 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;
}
use of software.amazon.awssdk.services.s3.model.GetObjectResponse in project aws-doc-sdk-examples by awsdocs.
the class GetObjectData method getObjectBytes.
// snippet-start:[s3.java2.getobjectdata.main]
public static void getObjectBytes(S3Client s3, String bucketName, String keyName, String path) {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(keyName).bucket(bucketName).build();
ResponseBytes<GetObjectResponse> objectBytes = s3.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
// Write the data to a local file
File myFile = new File(path);
OutputStream os = new FileOutputStream(myFile);
os.write(data);
System.out.println("Successfully obtained bytes from an S3 object");
os.close();
} catch (IOException ex) {
ex.printStackTrace();
} 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 KMSEncryptionExample method getEncryptedData.
// Obtain the encrypted data, decrypt it, and write the data to a text file
public static void getEncryptedData(S3Client s3, String bucketName, String objectName, String path, String keyId) {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(objectName).bucket(bucketName).build();
// Get the byte[] from the Amazon S3 bucket
ResponseBytes<GetObjectResponse> objectBytes = s3.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
// Decrypt the data by using the AWS Key Management Service
byte[] unEncryptedData = decryptData(data, keyId);
// Write the data to a local file
File myFile = new File(path);
OutputStream os = new FileOutputStream(myFile);
os.write(unEncryptedData);
System.out.println("Successfully obtained and decrypted bytes from the Amazon S3 bucket");
// Close the file
os.close();
} catch (IOException ex) {
ex.printStackTrace();
} 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 ExportEndpoints method downloadFromS3.
// Downloads files from an Amazon S3 bucket and writes them to the path location
public static void downloadFromS3(S3Client s3Client, String path, String s3BucketName, List<String> objectKeys) {
try {
for (String key : objectKeys) {
GetObjectRequest objectRequest = GetObjectRequest.builder().bucket(s3BucketName).key(key).build();
ResponseBytes<GetObjectResponse> objectBytes = s3Client.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
// Write the data to a local file
String fileSuffix = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
path = path + fileSuffix + ".gz";
File myFile = new File(path);
OutputStream os = new FileOutputStream(myFile);
os.write(data);
}
System.out.println("Download finished.");
} catch (S3Exception | NullPointerException | IOException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.model.GetObjectResponse in project aws-doc-sdk-examples by awsdocs.
the class PPEBoundingBoxFrame 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