List of usage examples for com.amazonaws.services.s3.model GetObjectRequest GetObjectRequest
public GetObjectRequest(String bucketName, String key, boolean isRequesterPays)
From source file:cloudExplorer.Get.java
License:Open Source License
public void run() { String message = null;//from w w w.j av a2s . c o m AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); File file = new File(what); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint); try { long t1 = System.currentTimeMillis(); S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket, what, version)); InputStream objectData = s3object.getObjectContent(); this.writeFile(objectData, destination); long t2 = System.currentTimeMillis(); long diff = t2 - t1; if (!mainFrame.perf) { if (terminal) { System.out.print("\nDownloaded: " + what + " in " + diff / 1000 + " second(s).\n"); } else { mainFrame.jTextArea1.append("\nDownloaded: " + what + " in " + diff / 1000 + " second(s)."); mainFrame.calibrateTextArea(); } } } catch (AmazonServiceException ase) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } catch (Exception get) { } calibrate(); }
From source file:com.emc.ecs.sync.model.object.S3ObjectVersion.java
License:Open Source License
@Override public InputStream createSourceInputStream() { if (isDirectory()) return null; return new BufferedInputStream( s3.getObject(new GetObjectRequest(bucketName, key, versionId)).getObjectContent(), getParentPlugin().getBufferSize()); }
From source file:com.netflix.spinnaker.front50.model.S3StorageService.java
License:Apache License
@Override public <T extends Timestamped> Collection<T> listObjectVersions(ObjectType objectType, String objectKey, int maxResults) throws NotFoundException { try {//from w w w. j a va 2s .c o m VersionListing versionListing = amazonS3.listVersions(new ListVersionsRequest(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename), null, null, null, maxResults)); return versionListing.getVersionSummaries().stream().map(s3VersionSummary -> { try { S3Object s3Object = amazonS3.getObject(new GetObjectRequest(bucket, buildS3Key(objectType.group, objectKey, objectType.defaultMetadataFilename), s3VersionSummary.getVersionId())); T item = deserialize(s3Object, (Class<T>) objectType.clazz); item.setLastModified(s3Object.getObjectMetadata().getLastModified().getTime()); return item; } catch (IOException e) { throw new IllegalStateException(e); } }).collect(Collectors.toList()); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404) { throw new NotFoundException(String.format("No item found with id of %s", objectKey.toLowerCase())); } throw e; } }
From source file:com.netflix.spinnaker.front50.model.S3Support.java
License:Apache License
public Collection<T> allVersionsOf(String id, int limit) throws NotFoundException { try {// w ww.j a va 2 s . co m VersionListing versionListing = amazonS3 .listVersions(new ListVersionsRequest(bucket, buildS3Key(id), null, null, null, limit)); return versionListing.getVersionSummaries().stream().map(s3VersionSummary -> { try { S3Object s3Object = amazonS3.getObject( new GetObjectRequest(bucket, buildS3Key(id), s3VersionSummary.getVersionId())); T item = deserialize(s3Object); item.setLastModified(s3Object.getObjectMetadata().getLastModified().getTime()); return item; } catch (IOException e) { throw new IllegalStateException(e); } }).collect(Collectors.toList()); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404) { throw new NotFoundException(String.format("No item found with id of %s", id.toLowerCase())); } throw e; } }
From source file:org.mule.module.s3.simpleapi.SimpleAmazonS3AmazonDevKitImpl.java
License:Open Source License
public S3Object getObject(@NotNull S3ObjectId objectId, @NotNull ConditionalConstraints conditionalConstraints) { Validate.notNull(objectId);/*from w w w .j av a 2 s . c o m*/ GetObjectRequest request = new GetObjectRequest(objectId.getBucketName(), objectId.getKey(), objectId.getVersionId()); conditionalConstraints.populate(request); return s3.getObject(request); }