Java Code Examples for com.amazonaws.services.s3.AmazonS3Client#deleteObject()
The following examples show how to use
com.amazonaws.services.s3.AmazonS3Client#deleteObject() .
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: S3ServiceBrokerV2IntegrationTests.java From s3-cf-service-broker with Apache License 2.0 | 6 votes |
private void testBucketOperations(String accessKey, String secretKey, String bucketName) throws IOException { AmazonS3Client instanceS3 = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey), awsClientConfiguration.toClientConfiguration()); assertTrue(instanceS3.doesBucketExist(bucketName)); String objectName = "testObject"; String objectContent = "Hello World!"; //set object content ByteArrayInputStream data = new ByteArrayInputStream(objectContent.getBytes()); PutObjectRequest putRequest = new PutObjectRequest(bucketName, objectName, data, new ObjectMetadata()); instanceS3.putObject(putRequest); //get object content GetObjectRequest getRequest = new GetObjectRequest(bucketName, objectName); BufferedReader reader = new BufferedReader(new InputStreamReader(instanceS3.getObject(getRequest).getObjectContent())); assertTrue(reader.readLine().equals(objectContent)); //delete object instanceS3.deleteObject(bucketName, objectName); }
Example 2
Source File: AWSTestUtils.java From aws-ant-tasks with Apache License 2.0 | 6 votes |
public static void emptyAndDeleteBucket(AmazonS3Client client, String bucketName) { ObjectListing objectListing = client.listObjects(bucketName); while (true) { for (Iterator<?> iterator = objectListing.getObjectSummaries() .iterator(); iterator.hasNext();) { S3ObjectSummary objectSummary = (S3ObjectSummary) iterator .next(); client.deleteObject(bucketName, objectSummary.getKey()); } if (objectListing.isTruncated()) { objectListing = client.listNextBatchOfObjects(objectListing); } else { break; } } client.deleteBucket(bucketName); }
Example 3
Source File: S3ClientImpl.java From exhibitor with Apache License 2.0 | 5 votes |
@Override public void deleteObject(String bucket, String key) throws Exception { RefCountedClient holder = client.get(); AmazonS3Client amazonS3Client = holder.useClient(); try { amazonS3Client.deleteObject(bucket, key); } finally { holder.release(); } }
Example 4
Source File: S3IntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testBucketOperations() throws Exception { AmazonS3Client s3Client = provider.getClient(); Assume.assumeNotNull("AWS client not null", s3Client); assertNoStaleBuckets(s3Client, "before"); try { try { S3Utils.createBucket(s3Client, bucketName); WildFlyCamelContext camelctx = new WildFlyCamelContext(); camelctx.getNamingContext().bind("s3Client", s3Client); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { String clientref = "amazonS3Client=#s3Client"; from("direct:upload").to("aws-s3://" + bucketName + "?" + clientref); from("aws-s3://" + bucketName + "?" + clientref).to("seda:read"); } }); try { camelctx.start(); try { // Put object Map<String, Object> headers = new HashMap<>(); headers.put(S3Constants.KEY, OBJECT_KEY); ProducerTemplate producer = camelctx.createProducerTemplate(); String content = "My bucket content"; String result1 = producer.requestBodyAndHeaders("direct:upload", content, headers, String.class); Assert.assertEquals(content, result1); ConsumerTemplate consumer = camelctx.createConsumerTemplate(); String result2 = consumer.receiveBody("seda:read", String.class); Assert.assertEquals(content, result2); } finally { camelctx.close(); } } finally { s3Client.deleteObject(bucketName, OBJECT_KEY); } } finally { S3Utils.deleteBucket(s3Client, bucketName); } } finally { assertNoStaleBuckets(s3Client, "after"); } }