use of software.amazon.awssdk.services.s3.model.S3Object in project exhibitor by soabase.
the class S3ConfigProvider method loadConfig.
@Override
public LoadedInstanceConfig loadConfig() throws Exception {
Date lastModified;
Properties properties = new Properties();
S3Object object = getConfigObject();
if (object != null) {
try {
lastModified = object.getObjectMetadata().getLastModified();
properties.load(object.getObjectContent());
} finally {
CloseableUtils.closeQuietly(object.getObjectContent());
}
} else {
lastModified = new Date(0L);
}
PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaults);
return new LoadedInstanceConfig(config, lastModified.getTime());
}
use of software.amazon.awssdk.services.s3.model.S3Object in project XRTB by benmfaul.
the class AwsCommander method load.
/**
* Load the file or s3 object.
* @param parts String[]. An array of tokens.
* @return String. The message returned from the load command.
* @throws Exception on I/O errirs.
*/
String load(String[] parts) throws Exception {
String otype = null;
String symbolName = null;
String name;
// file or S3
String type = parts[1];
// }
if (type.equalsIgnoreCase("S3")) {
// bloom, cache, cuckoo.
otype = parts[2];
name = parts[4];
// name of the object
symbolName = parts[3];
if (!symbolName.startsWith("$"))
symbolName = "$" + symbolName;
} else
// file name
name = parts[2];
if (type.equals("file")) {
return Configuration.getInstance().readData(parts[2]);
}
S3Object object = Configuration.s3.getObject(new GetObjectRequest(Configuration.s3_bucket, name));
long size = Configuration.s3.getObjectMetadata(Configuration.s3_bucket, name).getContentLength();
return Configuration.getInstance().readData(otype, symbolName, object, size);
}
use of software.amazon.awssdk.services.s3.model.S3Object in project aws-doc-sdk-examples by awsdocs.
the class GeneratePresignedUrlAndUploadObject method main.
public static void main(String[] args) throws IOException {
Regions clientRegion = Regions.DEFAULT_REGION;
String bucketName = "*** Bucket name ***";
String objectKey = "*** Object key ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).withRegion(clientRegion).build();
// Set the pre-signed URL to expire after one hour.
java.util.Date expiration = new java.util.Date();
long expTimeMillis = expiration.getTime();
expTimeMillis += 1000 * 60 * 60;
expiration.setTime(expTimeMillis);
// Generate the pre-signed URL.
System.out.println("Generating pre-signed URL.");
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey).withMethod(HttpMethod.PUT).withExpiration(expiration);
URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
// Create the connection and use it to upload the new object using the pre-signed URL.
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write("This text uploaded as an object via presigned URL.");
out.close();
// Check the HTTP response code. To complete the upload and make the object available,
// you must interact with the connection object in some way.
connection.getResponseCode();
System.out.println("HTTP response code: " + connection.getResponseCode());
// Check to make sure that the object was uploaded successfully.
S3Object object = s3Client.getObject(bucketName, objectKey);
System.out.println("Object " + object.getKey() + " created in bucket " + object.getBucketName());
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
e.printStackTrace();
} catch (SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
use of software.amazon.awssdk.services.s3.model.S3Object in project aws-doc-sdk-examples by awsdocs.
the class S3Service method listBucketObjects.
// Returns the names of all images in the given bucket.
public List<String> listBucketObjects(String bucketName) {
S3Client s3 = getClient();
String keyName;
List<String> keys = new ArrayList<>();
try {
ListObjectsRequest listObjects = ListObjectsRequest.builder().bucket(bucketName).build();
ListObjectsResponse res = s3.listObjects(listObjects);
List<S3Object> objects = res.contents();
for (S3Object myValue : objects) {
keyName = myValue.key();
keys.add(keyName);
}
return keys;
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.s3.model.S3Object in project aws-doc-sdk-examples by awsdocs.
the class VPCS3Example method listBucketObjects.
// snippet-start:[s3.java2.vpc.example.main]
public static void listBucketObjects(S3Client s3, String bucketName) {
try {
ListObjectsRequest listObjects = ListObjectsRequest.builder().bucket(bucketName).build();
ListObjectsResponse res = s3.listObjects(listObjects);
List<S3Object> objects = res.contents();
for (S3Object s3Object : objects) {
System.out.print("\n The name of the key is " + s3Object.key());
System.out.print("\n The object is " + convertBToKb(s3Object.size()) + " KBs");
System.out.print("\n The owner is " + s3Object.owner());
}
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations