use of software.amazon.awssdk.services.s3.model.S3Object in project jackrabbit-oak by apache.
the class S3Backend method read.
@Override
public InputStream read(DataIdentifier identifier) throws DataStoreException {
long start = System.currentTimeMillis();
String key = getKeyName(identifier);
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
S3Object object = s3service.getObject(bucket, key);
InputStream in = object.getObjectContent();
LOG.debug("[{}] read took [{}]ms", identifier, (System.currentTimeMillis() - start));
return in;
} catch (AmazonServiceException e) {
throw new DataStoreException("Object not found: " + key, e);
} finally {
if (contextClassLoader != null) {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
}
use of software.amazon.awssdk.services.s3.model.S3Object in project herd by FINRAOS.
the class S3DaoTest method testGetPropertiesHandleGenericException.
@Test
public void testGetPropertiesHandleGenericException() throws Exception {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
JavaPropertiesHelper originalJavaPropertiesHelper = (JavaPropertiesHelper) ReflectionTestUtils.getField(s3Dao, "javaPropertiesHelper");
JavaPropertiesHelper mockJavaPropertiesHelper = mock(JavaPropertiesHelper.class);
ReflectionTestUtils.setField(s3Dao, "javaPropertiesHelper", mockJavaPropertiesHelper);
try {
String bucketName = "bucketName";
String key = "key";
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
S3Object s3Object = new S3Object();
s3Object.setObjectContent(new ByteArrayInputStream(new byte[] { 0 }));
when(mockS3Operations.getS3Object(any(), any())).thenReturn(s3Object);
when(mockJavaPropertiesHelper.getProperties(any(InputStream.class))).thenThrow(new RuntimeException("message"));
try {
s3Dao.getProperties(bucketName, key, s3FileTransferRequestParamsDto);
fail();
} catch (Exception e) {
assertEquals(RuntimeException.class, e.getClass());
assertEquals("message", e.getMessage());
}
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
ReflectionTestUtils.setField(s3Dao, "javaPropertiesHelper", originalJavaPropertiesHelper);
}
}
use of software.amazon.awssdk.services.s3.model.S3Object in project tutorials by eugenp.
the class S3Application method main.
public static void main(String[] args) throws IOException {
// set-up the client
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_EAST_2).build();
AWSS3Service awsService = new AWSS3Service(s3client);
bucketName = "baeldung-bucket";
// creating a bucket
if (awsService.doesBucketExist(bucketName)) {
System.out.println("Bucket name is not available." + " Try again with a different Bucket name.");
return;
}
awsService.createBucket(bucketName);
// list all the buckets
for (Bucket s : awsService.listBuckets()) {
System.out.println(s.getName());
}
// deleting bucket
awsService.deleteBucket("baeldung-bucket-test2");
// uploading object
awsService.putObject(bucketName, "Document/hello.txt", new File("/Users/user/Document/hello.txt"));
// listing objects
ObjectListing objectListing = awsService.listObjects(bucketName);
for (S3ObjectSummary os : objectListing.getObjectSummaries()) {
System.out.println(os.getKey());
}
// downloading an object
S3Object s3object = awsService.getObject(bucketName, "Document/hello.txt");
S3ObjectInputStream inputStream = s3object.getObjectContent();
FileUtils.copyInputStreamToFile(inputStream, new File("/Users/user/Desktop/hello.txt"));
// copying an object
awsService.copyObject("baeldung-bucket", "picture/pic.png", "baeldung-bucket2", "Document/picture.png");
// deleting an object
awsService.deleteObject(bucketName, "Document/hello.txt");
// deleting multiple objects
String[] objkeyArr = { "Document/hello2.txt", "Document/picture.png" };
DeleteObjectsRequest delObjReq = new DeleteObjectsRequest("baeldung-bucket").withKeys(objkeyArr);
awsService.deleteObjects(delObjReq);
}
use of software.amazon.awssdk.services.s3.model.S3Object in project spring-integration-aws by spring-projects.
the class S3Session method read.
@Override
public void read(String source, OutputStream outputStream) throws IOException {
String[] bucketKey = splitPathToBucketAndKey(source, true);
S3Object s3Object = this.amazonS3.getObject(bucketKey[0], bucketKey[1]);
S3ObjectInputStream objectContent = s3Object.getObjectContent();
try {
StreamUtils.copy(objectContent, outputStream);
} finally {
objectContent.close();
}
}
use of software.amazon.awssdk.services.s3.model.S3Object in project spring-integration-aws by spring-projects.
the class S3Session method readRaw.
@Override
public InputStream readRaw(String source) throws IOException {
String[] bucketKey = splitPathToBucketAndKey(source, true);
S3Object s3Object = this.amazonS3.getObject(bucketKey[0], bucketKey[1]);
return s3Object.getObjectContent();
}
Aggregations