/** * Makes a call to the operation specified by the waiter by taking the * corresponding request and returns the corresponding result * * @param headObjectRequest * Corresponding request for the operation * @return Corresponding result of the operation */ @Override public ObjectMetadata apply(GetObjectMetadataRequest headObjectRequest) { return client.getObjectMetadata(headObjectRequest); } }
private AmazonS3 s3; ... public boolean exists(String path, String name) { try { s3.getObjectMetadata(bucket, getS3Path(path) + name); } catch(AmazonServiceException e) { return false; } return true; }
/** * Returns an object representing the details of an item in S3. The object is returned without the object's data. * * @param bucket * the bucket containing the object. * @param objectKey * the key identifying the object. * @return the object with the given key in S3, including only general details and metadata (not the data input * stream) * @throws SdkClientException */ private ObjectMetadata getS3ObjectDetails( Bucket bucket, String objectKey ) throws SdkClientException { return s3Client.getObjectMetadata( bucket.getName(), objectKey ); }
public ObjectMetadata getObjectMetadata(String bucket, String key) { final GetObjectMetadataRequest getObjectMetadataRequest = serverSideEncryption.decorate( new GetObjectMetadataRequest(bucket, key) ); return amazonS3.getObjectMetadata(getObjectMetadataRequest); }
public static boolean isValidFile(AmazonS3 s3, String bucketName, String path) throws AmazonClientException, AmazonServiceException { boolean isValidFile = true; try { ObjectMetadata objectMetadata = s3.getObjectMetadata(bucketName, path); } catch (AmazonS3Exception s3e) { if (s3e.getStatusCode() == 404) { // i.e. 404: NoSuchKey - The specified key does not exist isValidFile = false; } else { throw s3e; // rethrow all S3 exceptions other than 404 } } return isValidFile; }
private static ObjectMetadata getObjectMetadataForKey(Key k) { String[] bk = decodeKey(k); assert (bk.length == 2); return getClient().getObjectMetadata(bk[0], bk[1]); }
@Override public long getFileSize(Path remotePath) throws BackupRestoreException { return s3Client.getObjectMetadata(getShard(), remotePath.toString()).getContentLength(); }
/** * Returns {@code true} if mapping presents for the provided key. * * @param key Key to check mapping for. * @return {@code true} if mapping presents for key. * @throws AmazonClientException If an error occurs while querying Amazon S3. */ boolean hasKey(String key) throws AmazonClientException { assert !F.isEmpty(key); try { return s3.getObjectMetadata(bucketName, key).getContentLength() != 0; } catch (AmazonServiceException e) { if (e.getStatusCode() != 404) throw e; } return false; }
/** * Returns the part size of the part * * @param getObjectRequest the request to check * @param s3 the s3 client * @param partNumber the part number * @return the part size */ @SdkInternalApi public static long getPartSize(GetObjectRequest getObjectRequest, AmazonS3 s3, int partNumber) { ValidationUtils.assertNotNull(s3, "S3 client"); ValidationUtils.assertNotNull(getObjectRequest, "GetObjectRequest"); GetObjectMetadataRequest getObjectMetadataRequest = RequestCopyUtils.createGetObjectMetadataRequestFrom(getObjectRequest) .withPartNumber(partNumber); return s3.getObjectMetadata(getObjectMetadataRequest).getContentLength(); }
try { STATS.newMetadataCall(); return s3.getObjectMetadata(getBucketName(uri), keyFromPath(path));
/** * Returns the part count of the object represented by the getObjectRequest. * * @param getObjectRequest * The request to check. * @param s3 * The Amazon s3 client. * * @return The number of parts in the object if it is multipart object, otherwise returns null. */ public static Integer getPartCount(GetObjectRequest getObjectRequest, AmazonS3 s3) { ValidationUtils.assertNotNull(s3, "S3 client"); ValidationUtils.assertNotNull(getObjectRequest, "GetObjectRequest"); GetObjectMetadataRequest getObjectMetadataRequest = RequestCopyUtils.createGetObjectMetadataRequestFrom(getObjectRequest) .withPartNumber(1); return s3.getObjectMetadata(getObjectMetadataRequest).getPartCount(); }
/** * Returns the last byte number in a part of an object. * * @param s3 * The Amazon s3 client. * @param getObjectRequest * The request to check. * @param partNumber * The part in which we need the last byte number. * @return * The last byte number in the part. */ public static long getLastByteInPart(AmazonS3 s3, GetObjectRequest getObjectRequest, Integer partNumber) { ValidationUtils.assertNotNull(s3, "S3 client"); ValidationUtils.assertNotNull(getObjectRequest, "GetObjectRequest"); ValidationUtils.assertNotNull(partNumber, "partNumber"); GetObjectMetadataRequest getObjectMetadataRequest = RequestCopyUtils.createGetObjectMetadataRequestFrom(getObjectRequest) .withPartNumber(partNumber); ObjectMetadata metadata = s3.getObjectMetadata(getObjectMetadataRequest); return metadata.getContentRange()[1]; } }
final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectMetadataRequest);
.withVersionId(copyObjectRequest.getSourceVersionId()); ObjectMetadata metadata = srcS3.getObjectMetadata(getObjectMetadataRequest);
@Override public SingularityS3LogMetadata call() throws Exception { Optional<Long> maybeStartTime = Optional.absent(); Optional<Long> maybeEndTime = Optional.absent(); if (!search.isExcludeMetadata()) { GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(s3Object.getBucketName(), s3Object.getKey()); Map<String, String> objectMetadata = s3Client.getObjectMetadata(metadataRequest).getUserMetadata(); maybeStartTime = getMetadataAsLong(objectMetadata, SingularityS3Log.LOG_START_S3_ATTR); maybeEndTime = getMetadataAsLong(objectMetadata, SingularityS3Log.LOG_END_S3_ATTR); } if (search.isListOnly()) { return new SingularityS3LogMetadata(s3Object.getKey(), s3Object.getLastModified().getTime(), s3Object.getSize(), maybeStartTime, maybeEndTime); } else { GeneratePresignedUrlRequest getUrlRequest = new GeneratePresignedUrlRequest(s3Object.getBucketName(), s3Object.getKey()) .withMethod(HttpMethod.GET) .withExpiration(expireAt); String getUrl = s3Client.generatePresignedUrl(getUrlRequest).toString(); ResponseHeaderOverrides downloadHeaders = new ResponseHeaderOverrides(); downloadHeaders.setContentDisposition(CONTENT_DISPOSITION_DOWNLOAD_HEADER); downloadHeaders.setContentEncoding(CONTENT_ENCODING_DOWNLOAD_HEADER); GeneratePresignedUrlRequest downloadUrlRequest = new GeneratePresignedUrlRequest(s3Object.getBucketName(), s3Object.getKey()) .withMethod(HttpMethod.GET) .withExpiration(expireAt) .withResponseHeaders(downloadHeaders); String downloadUrl = s3Client.generatePresignedUrl(downloadUrlRequest).toString(); return new SingularityS3Log(getUrl, s3Object.getKey(), s3Object.getLastModified().getTime(), s3Object.getSize(), downloadUrl, maybeStartTime, maybeEndTime); } }
getObjectMetadataRequest.setSSECustomerKey(getObjectRequest.getSSECustomerKey()); final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectMetadataRequest);
private static ObjectMetadata getObjectMetadataForKey(Key k) { String[] bk = decodeKey(k); assert (bk.length == 2); return getClient().getObjectMetadata(bk[0], bk[1]); }
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.AmazonS3Exception; import org.apache.http.HttpStatus; try { AmazonS3 s3 = new AmazonS3Client(); S3Object object = s3.getObjectMetadata("my-bucket", "my-client"); } catch (AmazonS3Exception e) { if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) { // bucket/key does not exist } else { throw e; } }
@Override public long getAuxObjectSize(String auxItemTag) throws IOException { open(); String destinationKey = getDestinationKey(auxItemTag); try { return s3.getObjectMetadata(bucketName, destinationKey).getContentLength(); } catch (AmazonClientException ase) { logger.warning("Caught an AmazonClientException in S3AccessIO.getAuxObjectSize: " + ase.getMessage()); } return -1; }
.withSSECustomerKey(copyObjectRequest.getSourceSSECustomerKey()); final ObjectMetadata metadata = s3.getObjectMetadata(getObjectMetadataRequest);