Java 类com.amazonaws.services.s3.model.DeleteObjectRequest 实例源码

项目:stocator    文件:COSAPIClient.java   
@Override
public boolean delete(String hostName, Path path, boolean recursive) throws IOException {
  String obj = path.toString();
  if (path.toString().startsWith(hostName)) {
    obj = path.toString().substring(hostName.length());
  }
  LOG.debug("Object name to delete {}. Path {}", obj, path.toString());
  try {
    mClient.deleteObject(new DeleteObjectRequest(mBucket, obj));
    memoryCache.removeFileStatus(path.toString());
    return true;
  } catch (AmazonServiceException e) {
    if (e.getStatusCode() != 404) {
      throw new IOException(e);
    }
  }
  LOG.warn("Delete on {} not found. Nothing to delete");
  return false;
}
项目:gytheio    文件:S3ContentReferenceHandlerImpl.java   
@Override
public void delete(ContentReference contentReference) throws ContentIOException
{
    if (!isContentReferenceSupported(contentReference))
    {
        throw new ContentIOException("ContentReference not supported");
    }

    String remotePath = getRelativePath(contentReference.getUri());

    try
    {
        s3.deleteObject(new DeleteObjectRequest(s3BucketName, remotePath));
    } catch (AmazonClientException e)
    {
        throw new ContentIOException("Failed to delete content", e);
    }

}
项目:jcabi-s3    文件:AwsBucket.java   
@Override
public void remove(final String key) throws IOException {
    try {
        final AmazonS3 aws = this.regn.aws();
        final long start = System.currentTimeMillis();
        aws.deleteObject(new DeleteObjectRequest(this.bkt, key));
        Logger.info(
            this,
            "ocket '%s' removed in bucket '%s' in %[ms]s",
            key, this.bkt, System.currentTimeMillis() - start
        );
    } catch (final AmazonServiceException ex) {
        throw new IOException(
            String.format(
                "failed to remove '%s' bucket",
                this.bkt
            ),
            ex
        );
    }
}
项目:carina    文件:AmazonS3Manager.java   
/**
 * Delete file from Amazon S3 storage.
 * 
 * @param bucket
 *            - S3 Bucket name.
 * @param key
 *            - S3 storage path. Example:
 *            DEMO/TestSuiteName/TestMethodName/file.txt
 */
public void delete(String bucket, String key) {
    if (key == null) {
        throw new RuntimeException("Key is null!");
    }
    if (key.isEmpty()) {
        throw new RuntimeException("Key is empty!");
    }

    try {
        s3client.deleteObject(new DeleteObjectRequest(bucket, key));
    } catch (AmazonServiceException ase) {
        LOGGER.error("Caught an AmazonServiceException, which "
                + "means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.\n"
                + "Error Message:    " + ase.getMessage() + "\n"
                + "HTTP Status Code: " + ase.getStatusCode() + "\n"
                + "AWS Error Code:   " + ase.getErrorCode() + "\n"
                + "Error Type:       " + ase.getErrorType() + "\n"
                + "Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        LOGGER.error("Caught an AmazonClientException.\n"
                + "Error Message: " + ace.getMessage());
    }
}
项目:dataset-lib    文件:S3Provider.java   
public void remove(Object[] params) {
    AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
    try {
        s3client.deleteObject(new DeleteObjectRequest(bucketName, params[0].toString()));
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which " +
            "means your request made it " +
            "to Amazon S3, but was rejected with an error response" +
            " for some reason.");
        System.out.println("Error Message:" + ase.getMessage());
        System.out.println("HTTP Status Code:" + ase.getStatusCode());
        System.out.println("AWS Error Code:" + ase.getErrorCode());
        System.out.println("Error Type:" + ase.getErrorType());
        System.out.println("Request ID:" + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which " +
            "means the client encountered " +
            "an internal error while trying to " +
            "communicate with S3, " +
            "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }

}
项目:elasticsearch_my    文件:MockAmazonS3.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest)
        throws AmazonClientException, AmazonServiceException {
    String blobName = deleteObjectRequest.getKey();

    if (!blobs.containsKey(blobName)) {
        throw new AmazonS3Exception("[" + blobName + "] does not exist.");
    }

    blobs.remove(blobName);
}
项目:smart-security-camera    文件:S3ArchiveImageHandler.java   
@Override
public Parameters handleRequest(Parameters parameters, Context context) {

    context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

    // The archive location of the snapshot will be decided by the alert
    // flag
    String newFilename;
    if (parameters.getSendAlert()) {
        newFilename = parameters.getS3Key().replace("upload/", "archive/alerts/");
    } else {
        newFilename = parameters.getS3Key().replace("upload/", "archive/falsepositives/");
    }

    // Ensure that the first two hyphens are used to create sub-directories
    // in the file path
    newFilename = newFilename.replaceFirst("-", "/");
    newFilename = newFilename.replaceFirst("-", "/");

    // Using the S3 client, first copy the file to the archive, and then
    // delete the original
    AmazonS3 client = AmazonS3ClientBuilder.defaultClient();
    CopyObjectRequest copyObjectRequest = new CopyObjectRequest(parameters.getS3Bucket(), parameters.getS3Key(), parameters.getS3Bucket(), newFilename);
    client.copyObject(copyObjectRequest);
    DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(parameters.getS3Bucket(), parameters.getS3Key());
    client.deleteObject(deleteObjectRequest);

    // Place the new location in the parameters
    parameters.setS3ArchivedKey(newFilename);

    context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

    return parameters;
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest)
        throws SdkClientException, AmazonServiceException {
    deleteObjectRequest = beforeClientExecution(deleteObjectRequest);
    rejectNull(deleteObjectRequest,
        "The delete object request must be specified when deleting an object");

    rejectNull(deleteObjectRequest.getBucketName(), "The bucket name must be specified when deleting an object");
    rejectNull(deleteObjectRequest.getKey(), "The key must be specified when deleting an object");

    Request<DeleteObjectRequest> request = createRequest(deleteObjectRequest.getBucketName(), deleteObjectRequest.getKey(), deleteObjectRequest, HttpMethodName.DELETE);
    invoke(request, voidResponseHandler, deleteObjectRequest.getBucketName(), deleteObjectRequest.getKey());
}
项目:ibm-cos-sdk-java    文件:AmazonS3EncryptionClient.java   
@Override
public void deleteObject(DeleteObjectRequest req) {
    req.getRequestClientOptions().appendUserAgent(USER_AGENT);
    // Delete the object
    super.deleteObject(req);
    // If it exists, delete the instruction file.
    InstructionFileId ifid = new S3ObjectId(req.getBucketName(), req.getKey()).instructionFileId();

    DeleteObjectRequest instructionDeleteRequest = (DeleteObjectRequest) req.clone();
    instructionDeleteRequest.withBucketName(ifid.getBucket()).withKey(ifid.getKey());
    super.deleteObject(instructionDeleteRequest);
}
项目:tdl-auth    文件:RemoteTestBucket.java   
private void removeAllObjects() {
    amazonS3.listObjects(bucketName)
            .getObjectSummaries()
            .forEach(s3ObjectSummary -> {
                DeleteObjectRequest request = new DeleteObjectRequest(bucketName, s3ObjectSummary.getKey());
                amazonS3.deleteObject(request);
            });
}
项目:konker-platform    文件:AwsUploadRepository.java   
@Override
public void delete(String path) throws BusinessException {
    if (!Optional.ofNullable(path).isPresent()) {
        throw new BusinessException(Validations.INVALID_PATH.getCode());
    }
    client.getClient(credentials.getCredentials());
    try {
        s3Client.deleteObject(
                new DeleteObjectRequest(cdnConfig.getName(), path)
        );
    } catch (AmazonServiceException e) {
        throw new BusinessException(e.getMessage());
    }
}
项目:cloudkeeper    文件:S3ConnectionImpl.java   
@Override
public CompletableFuture<Void> moveObject(String fromBucketName, String fromKey, String toBucketName,
        String toKey) {
    CopyObjectRequest copyObjectResult
        = new CopyObjectRequest(fromBucketName, fromKey, toBucketName, toKey);
    DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(fromBucketName, fromKey);
    return CompletableFuture.runAsync(
        () -> {
            s3Client.copyObject(copyObjectResult);
            s3Client.deleteObject(deleteObjectRequest);
        },
        executorService
    );
}
项目:hawkbit-extensions    文件:S3Repository.java   
@Override
public void deleteBySha1(final String tenant, final String sha1Hash) {
    final String key = objectKey(tenant, sha1Hash);

    LOG.info("Deleting S3 object from bucket {} and key {}", s3Properties.getBucketName(), key);
    amazonS3.deleteObject(new DeleteObjectRequest(s3Properties.getBucketName(), key));
}
项目:omakase    文件:S3Client.java   
public void deleteObject(AWSCredentials awsCredentials, String region, String bucket, String key) {
    try {
        runtimeCredentialsProvider.setAwsCredentials(awsCredentials);
        amazonS3.setRegion(Region.getRegion(Regions.fromName(region)));
        amazonS3.deleteObject(new DeleteObjectRequest(bucket, key));
    } catch (AmazonClientException e) {
        throw new OmakaseRuntimeException(e);
    }
}
项目:datacollector    文件:AmazonS3Util.java   
static void copy(
    AmazonS3 s3Client,
    String srcBucket,
    String sourceKey,
    String destBucket,
    String destKey,
    boolean isMove
) {
  CopyObjectRequest cp = new CopyObjectRequest(srcBucket, sourceKey, destBucket, destKey);
  s3Client.copyObject(cp);
  if (isMove) {
    s3Client.deleteObject(new DeleteObjectRequest(srcBucket, sourceKey));
  }
}
项目:daikon    文件:S3DeletableResource.java   
@Override
public void delete() throws IOException {
    try {
        amazonS3.deleteObject(new DeleteObjectRequest(bucket, location));
        isDeleted = true;
    } catch (AmazonClientException e) {
        throw new IOException("Unable to delete '" + location + "' in bucket '" + bucket + "'.", e);
    }
}
项目:openbd-core    文件:Rename.java   
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
AmazonKey amazonKey = getAmazonKey(_session, argStruct);
AmazonS3 s3Client       = getAmazonS3(amazonKey);

    String bucket           = getNamedStringParam(argStruct, "bucket", null );
    String srckey           = getNamedStringParam(argStruct, "srckey", null );
    String deskey           = getNamedStringParam(argStruct, "destkey", null );
    String aes256key    = getNamedStringParam(argStruct, "aes256key", null );

if ( srckey != null && srckey.charAt( 0 ) == '/' )
    srckey  = srckey.substring(1);

if ( deskey != null && deskey.charAt( 0 ) == '/' )
    deskey  = deskey.substring(1);


    CopyObjectRequest cor = new CopyObjectRequest(bucket, srckey, bucket, deskey);

    if ( aes256key != null && !aes256key.isEmpty() ){
        cor.setSourceSSECustomerKey( new SSECustomerKey(aes256key) );
        cor.setDestinationSSECustomerKey( new SSECustomerKey(aes256key) );
    }


try {
    s3Client.copyObject(cor);
    s3Client.deleteObject(new DeleteObjectRequest(bucket, srckey));
    return cfBooleanData.TRUE;
} catch (Exception e) {
    throwException(_session, "AmazonS3: " + e.getMessage() );
    return cfBooleanData.FALSE;
}
}
项目:micro-genie    文件:S3FileStore.java   
/***
 * Deletes the specified file and returns the FilePath 
 */
@Override
public FilePath delete(final String drive, final String path) {
    final DeleteObjectRequest request = new DeleteObjectRequest(drive, path);
    LOGGER.debug("deleting file at drive: {} - path: {}", drive, path);
    this.client.deleteObject(request);
    return FilePath.as(drive, path);
}
项目:oodt    文件:S3DataTransferer.java   
@Override
public void deleteProduct(Product product) throws DataTransferException, IOException {
  for (Reference ref : product.getProductReferences()) {
    DeleteObjectRequest request = new DeleteObjectRequest(bucketName, stripProtocol(
        ref.getDataStoreReference(), true));
    try {
      s3Client.deleteObject(request);
    } catch (AmazonClientException e) {
      throw new DataTransferException(String.format(
          "Failed to delete product reference %s from S3", ref.getDataStoreReference()), e);
    }
  }
}
项目:oodt    文件:TestS3DataTransferer.java   
@Test
public void testDeleteProduct() throws DataTransferException, IOException {
  dataTransferer.deleteProduct(product);

   ArgumentCaptor<DeleteObjectRequest> argument = ArgumentCaptor
       .forClass(DeleteObjectRequest.class);
  verify(s3Client).deleteObject(argument.capture());

  DeleteObjectRequest request = argument.getValue();
  assertThat(request.getBucketName(), is(S3_BUCKET_NAME));
  assertThat(request.getKey(), is(EXPECTED_DATA_STORE_REF));
}
项目:cloudata    文件:S3ObjectStore.java   
@Override
public void delete(String path) throws IOException {
  log.debug("Delete file from {}/{}", bucket, path);

  DeleteObjectRequest request = new DeleteObjectRequest(bucket, path);
  s3Client.deleteObject(request);
}
项目:dsl-client-java    文件:AmazonS3Repository.java   
@Override
public Future<?> delete(final String bucket, final String key) {
    return executorService.submit(new Callable<Object>() {
        @Override
        public Object call() throws IOException {
            getS3Client().deleteObject(new DeleteObjectRequest(bucket, key));
            return null;
        }
    });
}
项目:elasticsearch_my    文件:AmazonS3Wrapper.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws AmazonClientException, AmazonServiceException {
    delegate.deleteObject(deleteObjectRequest);
}
项目:syndesis    文件:AmazonS3ClientMock.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws AmazonClientException, AmazonServiceException {
    throw new UnsupportedOperationException();
}
项目:syndesis    文件:AmazonS3ClientMock.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws AmazonClientException, AmazonServiceException {
    throw new UnsupportedOperationException();
}
项目:syndesis    文件:AmazonS3ClientMock.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws AmazonClientException, AmazonServiceException {
    throw new UnsupportedOperationException();
}
项目:connectors    文件:AmazonS3ClientMock.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws AmazonClientException, AmazonServiceException {
    throw new UnsupportedOperationException();
}
项目:connectors    文件:AmazonS3ClientMock.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws AmazonClientException, AmazonServiceException {
    throw new UnsupportedOperationException();
}
项目:connectors    文件:AmazonS3ClientMock.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws AmazonClientException, AmazonServiceException {
    throw new UnsupportedOperationException();
}
项目:aws-photosharing-example    文件:ContentHelper.java   
public void deleteContent(String p_bucket_name, String p_s3_key) throws AmazonClientException {
    if (s3Client.doesBucketExist(p_bucket_name)) {
        DeleteObjectRequest delete_req = new DeleteObjectRequest(p_bucket_name, p_s3_key);
        s3Client.deleteObject(delete_req);
    }
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public void deleteObject(String bucketName, String key)
        throws SdkClientException, AmazonServiceException {
    deleteObject(new DeleteObjectRequest(bucketName, key));
}
项目:S3Decorators    文件:S3Decorator.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws SdkClientException, AmazonServiceException {
  run(() -> getDelegate().deleteObject(deleteObjectRequest));
}
项目:cloudkeeper    文件:S3ConnectionImpl.java   
@Override
public CompletableFuture<Void> deleteObject(String bucketName, String key) {
    DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, key);
    return CompletableFuture.runAsync(() -> s3Client.deleteObject(deleteObjectRequest), executorService);
}
项目:Sqawsh    文件:PageManagerTest.java   
@Test
public void testRefreshAllPagesCorrectlyCallsS3() throws Exception {

  initialisePageManager();

  // Set up S3 expectations for upload (without copy) for each valid date:
  // Transfer interface is implemented by Uploads, Downloads, and Copies
  Transfer mockTransfer = mockery.mock(Transfer.class);
  mockery.checking(new Expectations() {
    {
      allowing(mockTransfer).isDone();
      will(returnValue(true));
      allowing(mockTransfer).waitForCompletion();
    }
  });
  mockTransferManager = mockery.mock(IS3TransferManager.class);
  // Just check S3 methods called correct number of times - don't bother
  // checking argument details.
  final Sequence refreshSequence = mockery.sequence("refresh");
  mockery.checking(new Expectations() {
    {
      // 2 uploads for each date + 3 uploads for the index pages + 1 upload
      // for the validdates json + 1 upload for the famous players json.
      exactly(2 * validDates.size() + 5).of(mockTransferManager).upload(
          with(any(PutObjectRequest.class)));
      will(returnValue(mockTransfer));
      inSequence(refreshSequence);

      // We do _not_ have the copy in this case
      never(mockTransferManager).copy(with(anything()));
    }
  });
  // Delete previous day's bookings and cached data at end
  mockS3Client = mockery.mock(AmazonS3.class);
  mockery.checking(new Expectations() {
    {
      exactly(2).of(mockS3Client).deleteObject(with(aNonNull(DeleteObjectRequest.class)));
      // Ensures this delete occurs after uploads of new pages and cached data
      inSequence(refreshSequence);

      exactly(1).of(mockTransferManager).getAmazonS3Client();
      will(returnValue(mockS3Client));
    }
  });
  pageManager.setS3TransferManager(mockTransferManager);

  // ACT
  pageManager.refreshAllPages(validDates, apiGatewayBaseUrl, revvingSuffix);
}
项目:spring-content    文件:DefaultS3StoreImpl.java   
private void delete(Resource resource) {
    if (resource.exists()) {
        client.deleteObject(new DeleteObjectRequest(bucket, resource.getFilename()));
    }
}
项目:Camel    文件:AmazonS3ClientMock.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest) throws AmazonClientException, AmazonServiceException {
    throw new UnsupportedOperationException();
}
项目:presto    文件:MockAmazonS3.java   
@Override
public void deleteObject(DeleteObjectRequest deleteObjectRequest)
        throws AmazonClientException
{
}
项目:bedrock    文件:StorageProvider.java   
public boolean deleteFile(String bucketName, String keyName) {
    initalizeS3();
    //AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());        
    s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
    return true;
}
项目:datacollector    文件:TestAmazonS3TargetForWholeFile.java   
public void deleteObjectsAfterVerificationInTarget(String objectKey) throws Exception {
  s3client.deleteObject(new DeleteObjectRequest(TARGET_BUCKET_NAME, objectKey));
}
项目:aws-lambda-unzip    文件:S3EventProcessorUnzip.java   
@Override
public String handleRequest(S3Event s3Event, Context context) {
    byte[] buffer = new byte[1024];
    try {
        for (S3EventNotificationRecord record: s3Event.getRecords()) {
            String srcBucket = record.getS3().getBucket().getName();

            // Object key may have spaces or unicode non-ASCII characters.
            String srcKey = record.getS3().getObject().getKey()
                    .replace('+', ' ');
            srcKey = URLDecoder.decode(srcKey, "UTF-8");

            // Detect file type
            Matcher matcher = Pattern.compile(".*\\.([^\\.]*)").matcher(srcKey);
            if (!matcher.matches()) {
                System.out.println("Unable to detect file type for key " + srcKey);
                return "";
            }
            String extension = matcher.group(1).toLowerCase();
            if (!"zip".equals(extension)) {
                System.out.println("Skipping non-zip file " + srcKey + " with extension " + extension);
                return "";
            }
            System.out.println("Extracting zip file " + srcBucket + "/" + srcKey);

            // Download the zip from S3 into a stream
            AmazonS3 s3Client = new AmazonS3Client();
            S3Object s3Object = s3Client.getObject(new GetObjectRequest(srcBucket, srcKey));
            ZipInputStream zis = new ZipInputStream(s3Object.getObjectContent());
            ZipEntry entry = zis.getNextEntry();

            while(entry != null) {
                String fileName = entry.getName();
                String mimeType = FileMimeType.fromExtension(FilenameUtils.getExtension(fileName)).mimeType();
                System.out.println("Extracting " + fileName + ", compressed: " + entry.getCompressedSize() + " bytes, extracted: " + entry.getSize() + " bytes, mimetype: " + mimeType);
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    outputStream.write(buffer, 0, len);
                }
                InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
                ObjectMetadata meta = new ObjectMetadata();
                meta.setContentLength(outputStream.size());
                meta.setContentType(mimeType);
                s3Client.putObject(srcBucket, FilenameUtils.getFullPath(srcKey) + fileName, is, meta);
                is.close();
                outputStream.close();
                entry = zis.getNextEntry();
            }
            zis.closeEntry();
            zis.close();

            //delete zip file when done
            System.out.println("Deleting zip file " + srcBucket + "/" + srcKey + "...");
            s3Client.deleteObject(new DeleteObjectRequest(srcBucket, srcKey));
            System.out.println("Done deleting");
        }
        return "Ok";
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}