use of org.jets3t.service.model.S3Bucket in project hadoop by apache.
the class Jets3tNativeFileSystemStore method initialize.
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
S3Credentials s3Credentials = new S3Credentials();
s3Credentials.initialize(uri, conf);
try {
AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey());
this.s3Service = new RestS3Service(awsCredentials);
} catch (S3ServiceException e) {
handleException(e);
}
multipartEnabled = conf.getBoolean("fs.s3n.multipart.uploads.enabled", false);
multipartBlockSize = Math.min(conf.getLong("fs.s3n.multipart.uploads.block.size", 64 * 1024 * 1024), MAX_PART_SIZE);
multipartCopyBlockSize = Math.min(conf.getLong("fs.s3n.multipart.copy.block.size", MAX_PART_SIZE), MAX_PART_SIZE);
serverSideEncryptionAlgorithm = conf.get("fs.s3n.server-side-encryption-algorithm");
bucket = new S3Bucket(uri.getHost());
}
use of org.jets3t.service.model.S3Bucket in project pentaho-kettle by pentaho.
the class S3ObjectsProviderTest method getS3ServiceMock.
private S3Service getS3ServiceMock(AWSCredentials credentials) throws Exception {
S3Service service = mock(S3Service.class);
when(service.listAllBuckets()).thenReturn(generateTestBuckets(TEST_USER_BUCKETS_NAMES));
// BUCKET2 - not empty bucket
when(service.listObjects((S3Bucket) argThat(this.new S3BucketArgumentMatcher(BUCKET2)))).thenReturn(bucket2Objects);
// BUCKET3 - empty bucket
when(service.listObjects((S3Bucket) argThat(this.new S3BucketArgumentMatcher(BUCKET3)))).thenReturn(bucket3Objects);
when(service.getObject(any(S3Bucket.class), any(String.class), any(), any(), any(), any(), any(), any())).thenReturn(testObject);
when(service.getObjectDetails(any(S3Bucket.class), any(String.class), any(), any(), any(), any())).thenReturn(testObject);
return service;
}
use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.
the class JetS3tLiveTest method whenFileMoved_NewInstanceIsSame.
@Test
public void whenFileMoved_NewInstanceIsSame() throws Exception {
// get a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
// create another bucket
S3Bucket tgtBucket = s3Service.createBucket(TgtBucket);
// Put a binary file
S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
s3Service.putObject(BucketName, fileObject);
// Copy it
s3Service.moveObject(BucketName, "test.jpg", TgtBucket, new S3Object("spidey.jpg"), false);
// Download
S3Object newFileObject = s3Service.getObject(TgtBucket, "spidey.jpg");
// Save to a different name
File newFile = new File("src/test/resources/spidey.jpg");
Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
// Get hashes and compare
String origMD5 = getFileMD5("src/test/resources/test.jpg");
String newMD5 = getFileMD5("src/test/resources/spidey.jpg");
assertTrue(origMD5.equals(newMD5));
// Clean up
deleteBucket();
s3Service.deleteObject(TgtBucket, "spidey.jpg");
s3Service.deleteBucket(TgtBucket);
}
use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.
the class JetS3tLiveTest method whenFileRenamed_NewNameIsSame.
@Test
public void whenFileRenamed_NewNameIsSame() throws Exception {
// get a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
// Put a binary file
S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
s3Service.putObject(BucketName, fileObject);
// Copy it
s3Service.renameObject(BucketName, "test.jpg", new S3Object("spidey.jpg"));
// Download
S3Object newFileObject = s3Service.getObject(BucketName, "spidey.jpg");
// Save to a different name
File newFile = new File("src/test/resources/spidey.jpg");
Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
// Get hashes and compare
String origMD5 = getFileMD5("src/test/resources/test.jpg");
String newMD5 = getFileMD5("src/test/resources/spidey.jpg");
assertTrue(origMD5.equals(newMD5));
// Clean up
deleteObject("test.jpg");
deleteObject("spidey.jpg");
deleteBucket();
}
use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.
the class JetS3tLiveTest method whenFileCopied_CopyIsSame.
@Test
public void whenFileCopied_CopyIsSame() throws Exception {
// get a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
// Put a binary file
S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
s3Service.putObject(BucketName, fileObject);
// Copy it
S3Object targetObject = new S3Object("testcopy.jpg");
s3Service.copyObject(BucketName, "test.jpg", BucketName, targetObject, false);
// Download
S3Object newFileObject = s3Service.getObject(BucketName, "testcopy.jpg");
// Save to a different name
File newFile = new File("src/test/resources/testcopy.jpg");
Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
// Get hashes and compare
String origMD5 = getFileMD5("src/test/resources/test.jpg");
String newMD5 = getFileMD5("src/test/resources/testcopy.jpg");
assertTrue(origMD5.equals(newMD5));
// Clean up
deleteObject("test.jpg");
deleteObject("testcopy.jpg");
deleteBucket();
}
Aggregations