@Override public S3Object getS3ObjectStream() { return getObject(getObjectRequest); }
@Override public S3Object getObject(String bucketName, String key) throws SdkClientException, AmazonServiceException { return getObject(new GetObjectRequest(bucketName, key)); }
AmazonS3Client s3Client = new AmazonS3Client(myCredentials); File localFile = new File("localFilename"); ObjectMetadata object = s3Client.getObject(new GetObjectRequest("bucket", "s3FileName"), localFile);
private void downloadGraphSourceFiles(String graphId, File dir) throws IOException { File graphCacheDir = dir; if (!graphCacheDir.exists()) graphCacheDir.mkdirs(); File graphZipFile = new File(graphCacheDir, graphId + ".zip"); File extractedGraphDir = new File(graphCacheDir, graphId); if (extractedGraphDir.exists()) { FileUtils.deleteDirectory(extractedGraphDir); } extractedGraphDir.mkdirs(); S3Object graphZip = s3.getObject(graphBucket, graphId+".zip"); InputStream zipFileIn = graphZip.getObjectContent(); OutputStream zipFileOut = new FileOutputStream(graphZipFile); IOUtils.copy(zipFileIn, zipFileOut); IOUtils.closeQuietly(zipFileIn); IOUtils.closeQuietly(zipFileOut); unpackGraphZip(graphZipFile, extractedGraphDir); }
@Override public S3Object getObject(String bucket, String key) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { return amazonS3Client.getObject(bucket, key); } finally { holder.release(); } }
POINT_DIR.mkdirs(); S3Object obj = s3.getObject(pointsetBucket, pointSetId + ".json.gz"); ObjectMetadata objMet = obj.getObjectMetadata(); FileOutputStream fos = new FileOutputStream(cachedFile);
@Override public String getObjectAsString(String bucketName, String key) throws AmazonServiceException, SdkClientException { rejectNull(bucketName, "Bucket name must be provided"); rejectNull(key, "Object key must be provided"); S3Object object = getObject(bucketName, key); try { return IOUtils.toString(object.getObjectContent()); } catch (IOException e) { throw new SdkClientException("Error streaming content from S3 during download"); } finally { IOUtils.closeQuietly(object, log); } }
s3.getObject(graphBucket, graphId + ".zip"); } catch (AmazonServiceException e) { s3.putObject(graphBucket, graphId+".zip", graphDataZip);
private S3Object getS3ObjectAndMetadata(String bucket, String key, SSECustomerKey ssecLocal) { GetObjectRequest getObjectRequest; if (ssecLocal != null) { getObjectRequest = new GetObjectRequest(bucket, key).withSSECustomerKey(ssecLocal); } else { getObjectRequest = new GetObjectRequest(bucket, key); } return s3Client.getObject(getObjectRequest); }
LOG.info("Downloading graph input files."); graphDataDirectory.mkdirs(); S3Object graphDataZipObject = s3.getObject(graphBucket, graphId + ".zip"); ZipInputStream zis = new ZipInputStream(graphDataZipObject.getObjectContent()); try {
@Override public S3Object getS3ObjectStream() { return getObject(getObjectRequest); }
AmazonS3Client s3Client = new AmazonS3Client(myCredentials); //This is where the downloaded file will be saved File localFile = new File("localFilename"); //This returns an ObjectMetadata file but you don't have to use this if you don't want s3Client.getObject(new GetObjectRequest(bucketName, id.getId()), localFile); //Now your file will have your image saved boolean success = localFile.exists() && localFile.canRead();
@Override public S3Object getObject(String bucketName, String key) throws AmazonClientException, AmazonServiceException { return getObject(new GetObjectRequest(bucketName, key)); }
@Override public String getObjectAsString(String bucketName, String key) throws AmazonServiceException, AmazonClientException { assertParameterNotNull(bucketName, "Bucket name must be provided"); assertParameterNotNull(key, "Object key must be provided"); final S3Object object = getObject(bucketName, key); try { return IOUtils.toString(object.getObjectContent()); } catch (final IOException e) { throw new AmazonClientException("Error streaming content from S3 during download"); } }
/** * Same as {@link #downloadTo(File)} but allows specifying a request metric * collector. * * @param destination the file to download to. * @param requestMetricCollector the request metrics collector. * @return an instance of {@link ObjectMetadata} */ public ObjectMetadata downloadTo(final File destination, RequestMetricCollector requestMetricCollector) { final GetObjectRequest req = new GetObjectRequest(getBucketName(), getKey()) .withRequestMetricCollector(requestMetricCollector); return getAmazonS3Client().getObject(req, destination); }
@Test public void testDownloadToOutstream() { EasyMock.reset(mockS3); EasyMock.expect(mockS3.getRegion()).andReturn(Region.US_Standard); byte[] mockResponseBytes = "MyData".getBytes(StringUtils.UTF8); ByteArrayOutputStream bos = new ByteArrayOutputStream(); S3Object mockObj = EasyMock.createMock(S3Object.class); ByteArrayInputStream bis = new ByteArrayInputStream(mockResponseBytes); S3ObjectInputStream s3is = new S3ObjectInputStream(bis, null); EasyMock.expect(mockS3.getObject(anyObject(GetObjectRequest.class))).andReturn(mockObj); EasyMock.expect(mockObj.getObjectContent()).andReturn(s3is); EasyMock.expect(mockObj.getObjectMetadata()).andReturn(new ObjectMetadata()); EasyMock.replay(mockS3, mockObj); mapper.getS3ClientCache().useClient(mockS3); S3Link link = mapper.createS3Link(bucket, key); link.downloadTo(bos); EasyMock.verify(mockS3, mockObj); assertArrayEquals(mockResponseBytes, bos.toByteArray()); }
@Test public void testDownloadToFile() throws IOException { EasyMock.reset(mockS3); EasyMock.expect(mockS3.getRegion()).andReturn(Region.US_Standard); File testFile = new File("S3LinkTest"); if (testFile.exists()) { assertTrue(testFile.delete()); } assertTrue(testFile.createNewFile()); S3Object mockObj = EasyMock.createMock(S3Object.class); EasyMock.expect(mockS3.getObject(anyObject(GetObjectRequest.class), eq(testFile))) .andReturn(null); EasyMock.replay(mockS3, mockObj); mapper.getS3ClientCache().useClient(mockS3); S3Link link = mapper.createS3Link(bucket, key); link.downloadTo(testFile); EasyMock.verify(mockS3, mockObj); assertTrue(testFile.delete()); }
final GetObjectRequest req = new GetObjectRequest(getBucketName(), getKey()) .withRequestMetricCollector(requestMetricCollector); final S3Object s3Object = getAmazonS3Client().getObject(req); final S3ObjectInputStream objectContent = s3Object.getObjectContent();
@Override public S3Object getObject(String bucketName, String key) throws SdkClientException, AmazonServiceException { S3Object o = super.getObject(bucketName, key); LOG.debug("Wrapping in InconsistentS3Object for key {}", key); return new InconsistentS3Object(o, policy); }
@Override public InputStream getInputStream(BinaryKey key) throws BinaryStoreException { try { S3Object s3Object = s3Client.getObject(bucketName, key.toString()); return s3Object.getObjectContent(); } catch (AmazonClientException e) { throw new BinaryStoreException(e); } }