Java Code Examples for com.amazonaws.services.s3.model.PutObjectRequest#getKey()
The following examples show how to use
com.amazonaws.services.s3.model.PutObjectRequest#getKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockAmazonS3.java From crate with Apache License 2.0 | 6 votes |
@Override public PutObjectResult putObject(final PutObjectRequest request) throws AmazonClientException { assertThat(request.getBucketName(), equalTo(bucket)); assertThat(request.getMetadata().getSSEAlgorithm(), serverSideEncryption ? equalTo("AES256") : nullValue()); assertThat(request.getCannedAcl(), notNullValue()); assertThat(request.getCannedAcl().toString(), cannedACL != null ? equalTo(cannedACL) : equalTo("private")); assertThat(request.getStorageClass(), storageClass != null ? equalTo(storageClass) : equalTo("STANDARD")); final String blobName = request.getKey(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { Streams.copy(request.getInputStream(), out); blobs.put(blobName, out.toByteArray()); } catch (IOException e) { throw new AmazonClientException(e); } return new PutObjectResult(); }
Example 2
Source File: InventoryReportLineWriterTest.java From s3-inventory-usage-examples with Apache License 2.0 | 4 votes |
@Test public void writeObjectToCsvSuccess() throws IOException{ String testSrcBucket = "testSrcBucket"; String testDestBucketName = "testDestBucketName"; String testDestPrefix = "testDestPrefix"; String testFileSchema = "Bucket, Key, Versionid, IsLatest, IsDeleteMaker, Size, LastModifiedDate," + "ETag, StorageClass, IsMultipartUploaded, ReplicationStatus"; InventoryManifest testInventoryManifest = buildInventoryManifest(testFileSchema); List<InventoryReportLine> testInventoryReportLine = buildInventoryReportStorgaeList(); InventoryReportLineWriter testCsvWriter = new InventoryReportLineWriter(mockS3Client, testDestBucketName, testDestPrefix, testSrcBucket, testInventoryManifest); when(mockS3Client.putObject(putObjectRequestCaptor.capture())).thenReturn(null); InventoryManifest.Locator testLocator = testCsvWriter.writeCsvFile(testInventoryReportLine); PutObjectRequest request = putObjectRequestCaptor.getValue(); // Test if bucketName and outputInventoryReportKey match in args assertThat(request.getBucketName(), is("testDestBucketName")); String actualKey = request.getKey(); List<String> keyList = Arrays.asList(actualKey.split("\\s*/\\s*")); assertThat(keyList.get(0), is("testDestPrefix")); assertThat(keyList.get(1), is("testSrcBucket")); assertThat(keyList.get(2), is("data")); // Test if the inputStream match when put object to S3 byte[] actualByteArray = IOUtils.toByteArray(request.getInputStream()); String actualInventoryReportString = IOUtils.toString(new GZIPInputStream( new ByteArrayInputStream(actualByteArray))); String expectedInventoryReportString = "testBucket1,testKey1,testVersionId1,testIsLatest1,testIsDeleteMaker1,testSize1,testLastModifiedDate1," + "testETag1,testStorage1,testMultiPartUploaded1,testReplicationStatus1\n" + "testBucket2,testKey2,testVersionId2,testIsLatest2,testIsDeleteMaker2,testSize2,testLastModifiedDate2," + "testETag2,testStorage2,testMultiPartUploaded2,testReplicationStatus2\n"; assertThat(actualInventoryReportString, is(expectedInventoryReportString)); // Test if the metaData match when put object to S3 long expectedMetaDataLength = actualByteArray.length; assertThat(request.getMetadata().getContentLength(), is(expectedMetaDataLength)); // Test if the return result of writeCsvFile() match the expected one InventoryManifest.Locator expectedLocator = new InventoryManifest.Locator(); expectedLocator.setKey(actualKey); long expectedSize = actualByteArray.length; expectedLocator.setSize(expectedSize); String expectedChecksum = DigestUtils.md5Hex(actualByteArray); expectedLocator.setMD5checksum(expectedChecksum); assertThat(testLocator, is(expectedLocator)); }