use of software.amazon.awssdk.services.s3.model.S3Exception 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.S3Exception in project pravega by pravega.
the class S3ChunkStorage method checkExists.
@Override
protected boolean checkExists(String chunkName) throws ChunkStorageException {
try {
val objectPath = getObjectPath(chunkName);
val response = client.headObject(HeadObjectRequest.builder().bucket(this.config.getBucket()).key(objectPath).build());
return true;
} catch (S3Exception e) {
if (e.awsErrorDetails().errorCode().equals(NO_SUCH_KEY)) {
return false;
} else {
throw convertException(chunkName, "checkExists", e);
}
}
}
use of software.amazon.awssdk.services.s3.model.S3Exception in project pravega by pravega.
the class S3ChunkStorage method convertException.
private ChunkStorageException convertException(String chunkName, String message, Exception e) {
ChunkStorageException retValue = null;
if (e instanceof ChunkStorageException) {
return (ChunkStorageException) e;
}
if (e instanceof S3Exception) {
S3Exception s3Exception = (S3Exception) e;
String errorCode = Strings.nullToEmpty(s3Exception.awsErrorDetails().errorCode());
if (errorCode.equals(NO_SUCH_KEY)) {
retValue = new ChunkNotFoundException(chunkName, message, e);
}
if (errorCode.equals(PRECONDITION_FAILED)) {
retValue = new ChunkAlreadyExistsException(chunkName, message, e);
}
if (errorCode.equals(INVALID_RANGE) || errorCode.equals(INVALID_ARGUMENT) || errorCode.equals(METHOD_NOT_ALLOWED) || s3Exception.awsErrorDetails().sdkHttpResponse().statusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
throw new IllegalArgumentException(chunkName, e);
}
if (errorCode.equals(ACCESS_DENIED)) {
retValue = new ChunkStorageException(chunkName, String.format("Access denied for chunk %s - %s.", chunkName, message), e);
}
}
if (retValue == null) {
retValue = new ChunkStorageException(chunkName, message, e);
}
return retValue;
}
use of software.amazon.awssdk.services.s3.model.S3Exception 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;
}
use of software.amazon.awssdk.services.s3.model.S3Exception in project aws-doc-sdk-examples by awsdocs.
the class MovieLensDatasetProvider method getObjectBytes.
// Checks to see if the dataset is already uploaded to s3.
public static boolean getObjectBytes(S3Client s3Client, String bucketName, String keyName) {
try {
GetObjectRequest objectRequest = GetObjectRequest.builder().key(keyName).bucket(bucketName).build();
ResponseBytes<GetObjectResponse> objectBytes = s3Client.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
return data.length > 0;
} catch (NoSuchKeyException | NoSuchBucketException ex) {
return false;
} catch (S3Exception s3Exception) {
System.err.println(s3Exception.awsErrorDetails().errorMessage());
System.exit(1);
}
return false;
}
Aggregations