List of usage examples for com.amazonaws.services.s3.model GetObjectRequest GetObjectRequest
public GetObjectRequest(String bucketName, String key)
From source file:org.gytheio.content.handler.s3.S3ContentReferenceHandlerImpl.java
License:Open Source License
@Override public boolean isContentReferenceExists(ContentReference contentReference) { if (!isContentReferenceSupported(contentReference)) { return false; }//from ww w.ja v a 2 s.co m try { String s3Url = getS3UrlFromHttpUrl(contentReference.getUri()); if (logger.isDebugEnabled()) { logger.debug("Checking existence of reference: " + s3Url); } // Get the object and retrieve the input stream S3Object object = s3.getObject(new GetObjectRequest(s3BucketName, getRelativePath(s3Url))); return object != null; } catch (AmazonServiceException e) { throw new ContentIOException("Failed to check existence of content: " + e.getMessage(), e); } catch (Throwable t) { // Otherwise don't really care why, just that it doesn't exist return false; } }
From source file:org.gytheio.content.handler.s3.S3ContentReferenceHandlerImpl.java
License:Open Source License
@Override public InputStream getInputStream(ContentReference contentReference, boolean waitForAvailability) throws ContentIOException { if (!isContentReferenceSupported(contentReference)) { throw new ContentIOException("ContentReference not supported"); }/*from ww w . ja v a 2 s . c o m*/ try { String s3Url = getS3UrlFromHttpUrl(contentReference.getUri()); if (logger.isDebugEnabled()) { logger.debug("Getting remote input stream for reference: " + s3Url); } // Get the object and retrieve the input stream S3Object object = s3.getObject(new GetObjectRequest(s3BucketName, getRelativePath(s3Url))); return object.getObjectContent(); } catch (Throwable t) { throw new ContentIOException("Failed to read content", t); } }
From source file:org.icgc.dcc.storage.server.repository.s3.S3DownloadService.java
License:Open Source License
private S3FetchedObject fetchObject(String bucketName, String objectMetaKey) { // Perform actual retrieval of object from S3/ObjectStore val request = new GetObjectRequest(bucketName, objectMetaKey); return new S3FetchedObject(s3Client.getObject(request)); }
From source file:org.icgc.dcc.storage.server.repository.s3.S3UploadStateStore.java
License:Open Source License
@Override @SneakyThrows//from w w w .j a va2s . c om public ObjectSpecification read(String objectId, String uploadId) { val uploadStateKey = getUploadStateKey(objectId, uploadId, META); try { val request = new GetObjectRequest(bucketNamingService.getStateBucketName(objectId), uploadStateKey); val obj = s3Client.getObject(request); try (val inputStream = obj.getObjectContent()) { return MAPPER.readValue(inputStream, ObjectSpecification.class); } } catch (AmazonServiceException e) { if (e.isRetryable()) { throw new RetryableException(e); } else { throw new IdNotFoundException(uploadId); } } catch (JsonParseException | JsonMappingException e) { log.error("Error reading specification for objectId {} and uploadId {}", objectId, uploadId); throw new NotRetryableException(e); } }
From source file:org.jdamico.s3.components.S3Component.java
License:Apache License
public boolean isValidFile(AppProperties appProperties, String keyName) throws TopLevelException { AmazonS3 s3client = getS3Client(appProperties); boolean isValidFile = true; try {/*from ww w .jav a2 s . com*/ S3Object object = s3client.getObject(new GetObjectRequest(appProperties.getBucketnName(), keyName)); ObjectMetadata objectMetadata = object.getObjectMetadata(); } catch (AmazonS3Exception s3e) { if (s3e.getStatusCode() == 404) { isValidFile = false; } else { throw new TopLevelException(appProperties, s3e); } } return isValidFile; }
From source file:org.nickelproject.util.streamUtil.S3InputStreamFactory.java
License:Apache License
@Override public InputStream getInputStream() { final S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, key)); return object.getObjectContent(); }
From source file:org.nuxeo.aws.elastictranscoder.AWSS3Handler.java
License:Open Source License
public Blob downloadFile(String inKey, String inFileName) throws IOException, RuntimeException { ObjectMetadata metadata = null;/*from w w w. j av a 2 s . com*/ // Create a temp. file String ext = Files.getFileExtension(inFileName); ext = StringUtils.isBlank(ext) ? "tmp" : ext; Blob result = Blobs.createBlobWithExtension("." + ext); File tmp = File.createTempFile("NxAWSET-", "." + Files.getFileExtension(inFileName)); tmp.deleteOnExit(); Framework.trackFile(tmp, this); try { GetObjectRequest gor = new GetObjectRequest(bucket, inKey); metadata = amazonS3.getObject(gor, tmp); } catch (AmazonServiceException ase) { String message = GenericAWSClient.buildDetailedMessageFromAWSException(ase); throw new RuntimeException(message); } catch (AmazonClientException ace) { String message = GenericAWSClient.buildDetailedMessageFromAWSException(ace); throw new RuntimeException(message); } if (metadata != null && tmp.exists()) { result = new FileBlob(tmp); result.setFilename(inFileName); result.setMimeType(metadata.getContentType()); } return result; }
From source file:org.nuxeo.liveconnect.importer.aws.LiveconnectS3Blobprovider.java
License:Apache License
@Override public InputStream getStream(ManagedBlob blob) throws IOException { LiveConnectFileInfo fileInfo = toFileInfo(blob); GetObjectRequest request = new GetObjectRequest(bucketName, fileInfo.getFileId()); S3Object object = amazonS3.getObject(request); return object.getObjectContent(); }
From source file:org.nuxeo.liveconnect.importer.aws.LiveconnectS3Blobprovider.java
License:Apache License
@Override protected LiveConnectFile retrieveFile(LiveConnectFileInfo fileInfo) throws IOException { // First, invalidate the Drive file cache in order to force call to API invalidateInCache("file_" + fileInfo.getFileId()); GetObjectRequest request = new GetObjectRequest(bucketName, fileInfo.getFileId()); S3Object object = amazonS3.getObject(request); return new S3LiveConnectFile(fileInfo, object); }
From source file:org.nuxeo.s3utils.S3HandlerImpl.java
License:Apache License
@Override public Blob downloadFile(String inKey, String inFileName) throws NuxeoException { ObjectMetadata metadata = null;/*from w ww . ja v a 2 s. c o m*/ Blob blob; try { blob = Blobs.createBlobWithExtension(".tmp"); } catch (IOException e) { throw new NuxeoException(e); } try { GetObjectRequest gor = new GetObjectRequest(currentBucket, inKey); metadata = s3.getObject(gor, blob.getFile()); } catch (AmazonServiceException ase) { String message = S3Handler.buildDetailedMessageFromAWSException(ase); throw new NuxeoException(message); } catch (AmazonClientException ace) { String message = S3Handler.buildDetailedMessageFromAWSException(ace); throw new NuxeoException(message); } if (metadata != null && blob.getFile().exists()) { if (StringUtils.isBlank(inFileName)) { int pos = inKey.lastIndexOf("/"); if (pos > -1) { inFileName = inKey.substring(pos + 1, inKey.length()); } else { inFileName = inKey; } } blob.setFilename(inFileName); blob.setMimeType(metadata.getContentType()); } return blob; }