Search in sources :

Example 16 with S3Object

use of org.jets3t.service.model.S3Object in project pentaho-kettle by pentaho.

the class S3ObjectsProviderTest method setUp.

@Before
public void setUp() throws Exception {
    bucket2Objects = generateTestS3ObjectsInBucket(BUCKET2, false);
    bucket3Objects = generateTestS3ObjectsInBucket(BUCKET3, true);
    testObject = new S3Object(BUCKET1, "tests3Object", "TestString");
    s3serviceMock = getS3ServiceMock(testUserCredentials);
    provider = new S3ObjectsProvider(s3serviceMock);
}
Also used : S3Object(org.jets3t.service.model.S3Object) Before(org.junit.Before)

Example 17 with S3Object

use of org.jets3t.service.model.S3Object 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);
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Object(org.jets3t.service.model.S3Object) Test(org.junit.Test)

Example 18 with S3Object

use of org.jets3t.service.model.S3Object 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();
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Object(org.jets3t.service.model.S3Object) Test(org.junit.Test)

Example 19 with S3Object

use of org.jets3t.service.model.S3Object 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();
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Object(org.jets3t.service.model.S3Object) Test(org.junit.Test)

Example 20 with S3Object

use of org.jets3t.service.model.S3Object in project tutorials by eugenp.

the class JetS3tLiveTest method givenStreamDataUploaded_StreamDataIsDownloaded.

@Test
public void givenStreamDataUploaded_StreamDataIsDownloaded() throws Exception {
    // get a bucket
    S3Bucket bucket = createBucket();
    assertNotNull(bucket);
    // Create a stream
    ByteArrayInputStream testStream = new ByteArrayInputStream("test stream".getBytes());
    // Create and populate object
    S3Object streamObject = new S3Object("stream");
    streamObject.setDataInputStream(testStream);
    streamObject.setContentLength(testStream.available());
    streamObject.setContentType("text/plain");
    // Put it
    s3Service.putObject(BucketName, streamObject);
    // Get it
    S3Object newStreamObject = s3Service.getObject(BucketName, "stream");
    // Convert back to string
    String testString = new BufferedReader(new InputStreamReader(newStreamObject.getDataInputStream())).lines().collect(Collectors.joining("\n"));
    assertTrue("test stream".equals(testString));
    // Clean up
    deleteObject("stream");
    deleteBucket();
}
Also used : S3Bucket(org.jets3t.service.model.S3Bucket) S3Object(org.jets3t.service.model.S3Object) Test(org.junit.Test)

Aggregations

S3Object (org.jets3t.service.model.S3Object)39 Test (org.junit.Test)16 S3ServiceException (org.jets3t.service.S3ServiceException)11 ServiceException (org.jets3t.service.ServiceException)11 RestS3Service (org.jets3t.service.impl.rest.httpclient.RestS3Service)11 S3Bucket (org.jets3t.service.model.S3Bucket)9 Date (java.util.Date)8 File (java.io.File)6 IOException (java.io.IOException)6 DataSegment (io.druid.timeline.DataSegment)5 URI (java.net.URI)5 StorageObject (org.jets3t.service.model.StorageObject)5 InputStream (java.io.InputStream)4 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 Pattern (java.util.regex.Pattern)3 S3Service (org.jets3t.service.S3Service)3 AWSCredentials (org.jets3t.service.security.AWSCredentials)3 FileUtils (io.druid.java.util.common.FileUtils)2 BufferedReader (java.io.BufferedReader)2