use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.
the class JetS3tLiveTest method givenStringUploaded_StringIsDownloaded.
@Test
public void givenStringUploaded_StringIsDownloaded() throws Exception {
// Get a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
uploadStringData();
// Download
S3Object stringObject = s3Service.getObject(BucketName, TestStringName);
// Process stream into a string
String downloadedString = new BufferedReader(new InputStreamReader(stringObject.getDataInputStream())).lines().collect(Collectors.joining("\n"));
// Verify
assertTrue(TestString.equals(downloadedString));
// Clean up for next test
deleteObject(TestStringName);
deleteBucket();
}
use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.
the class JetS3tLiveTest method givenBinaryFileUploaded_FileIsDownloaded.
@Test
public void givenBinaryFileUploaded_FileIsDownloaded() 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);
// Print info about type and name
log.info("Content type:" + fileObject.getContentType());
log.info("File object name is " + fileObject.getName());
// Download
S3Object newFileObject = s3Service.getObject(BucketName, "test.jpg");
// Save to a different name
File newFile = new File("src/test/resources/newtest.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/newtest.jpg");
assertTrue(origMD5.equals(newMD5));
// Clean up
deleteObject("test.jpg");
deleteBucket();
}
use of org.jets3t.service.model.S3Bucket in project tutorials by eugenp.
the class JetS3tLiveTest method givenString_Uploaded_StringInfoIsAvailable.
@Test
public void givenString_Uploaded_StringInfoIsAvailable() throws Exception {
// Create a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
// Upload a string
uploadStringData();
// Get the details
StorageObject objectDetailsOnly = s3Service.getObjectDetails(BucketName, TestStringName);
log.info("Content type: " + objectDetailsOnly.getContentType() + " length: " + objectDetailsOnly.getContentLength());
// Delete it
deleteObject(TestStringName);
// For next test
deleteBucket();
}
use of org.jets3t.service.model.S3Bucket in project airavata by apache.
the class BucketsLoader method load.
/**
* @param s3 S3Service
* @param s3Tree S3Tree
*/
public void load(final S3Service s3, final S3Tree s3Tree) {
new Thread(new Runnable() {
@Override
public void run() {
S3Bucket[] bucketArray;
try {
bucketArray = s3.listAllBuckets();
for (S3Bucket s3Bucket : bucketArray) {
DefaultMutableTreeNode tempTreeNode = s3Tree.addObject((DefaultMutableTreeNode) null, s3Bucket.getName());
if (BucketsLoader.this.canceled)
return;
S3Object[] s3ObjectArray = s3.listObjects(s3Bucket.getName());
for (S3Object s3Object : s3ObjectArray) {
String keyName = s3Object.getName();
if (keyName.contains("$")) {
keyName = keyName.substring(0, keyName.indexOf('_'));
}
s3Tree.addObject(tempTreeNode, keyName);
}
}
s3Tree.refresh();
if (bucketArray.length == 0) {
JOptionPane.showMessageDialog(BucketsLoader.this.parent, "Connection Failed!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
JOptionPane.showMessageDialog(BucketsLoader.this.parent, "Connection Successfully!", "Info", JOptionPane.INFORMATION_MESSAGE);
// already connect
S3TreeModel.getInstance().connect();
} catch (S3ServiceException ex) {
BucketsLoader.this.xbayaGUI.getErrorWindow().error(BucketsLoader.this.parent, "Cannot List S3 buckets", ex);
} finally {
BucketsLoader.this.loadingDialog.hide();
}
}
}).start();
this.loadingDialog.show();
}
Aggregations