List of usage examples for com.amazonaws.services.s3 AmazonS3 doesObjectExist
boolean doesObjectExist(String bucketName, String objectName) throws AmazonServiceException, SdkClientException;
From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java
License:Open Source License
/** * {@inheritDoc}//from w ww .ja v a2 s. c o m */ @Override public PutObjectResult putObject(AmazonS3 client, String bucketName, String key, File file) { if (client == null) { return null; } else if (StringUtil.isEmpty(bucketName)) { return null; } else if (StringUtil.isEmpty(key)) { return null; } else if (file == null) { return null; } PutObjectResult result = null; if (!client.doesObjectExist(bucketName, key)) { result = client.putObject(bucketName, key, file); } return result; }
From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java
License:Open Source License
/** * {@inheritDoc}/* w ww . ja v a 2s. c o m*/ */ @Override public PutObjectResult putObject(AmazonS3 client, String bucketName, String key, InputStream input, ObjectMetadata metadata) { if (client == null) { return null; } else if (StringUtil.isEmpty(bucketName)) { return null; } else if (StringUtil.isEmpty(key)) { return null; } else if (input == null) { return null; } if (metadata == null) { metadata = new ObjectMetadata(); } PutObjectResult result = null; if (!client.doesObjectExist(bucketName, key)) { result = client.putObject(bucketName, key, input, metadata); } return result; }
From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java
License:Open Source License
/** * {@inheritDoc}/*from w ww.jav a 2 s . co m*/ */ @Override public S3Object getObject(AmazonS3 client, String bucketName, String key) { if (client == null) { return null; } else if (StringUtil.isEmpty(bucketName)) { return null; } else if (StringUtil.isEmpty(key)) { return null; } S3Object object = null; if (client.doesObjectExist(bucketName, key)) { object = client.getObject(bucketName, key); } return object; }
From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java
License:Open Source License
/** * {@inheritDoc}/*from w ww. java2 s . c o m*/ */ @Override public ObjectListing getObjectList(AmazonS3 client, String bucketName, String prefix) { if (client == null) { return null; } else if (StringUtil.isEmpty(bucketName)) { return null; } else if (StringUtil.isEmpty(prefix)) { return null; } if (!client.doesObjectExist(bucketName, prefix)) { return null; } ObjectListing objectListing = null; if (prefix == null) { objectListing = client.listObjects(bucketName); } else { objectListing = client.listObjects(bucketName, prefix); } return objectListing; }
From source file:com.easarrive.aws.plugins.common.service.impl.S3Service.java
License:Open Source License
/** * {@inheritDoc}/*w w w. j a v a2s .c o m*/ */ @Override public void deleteObject(AmazonS3 client, String bucketName, String key) { if (client == null) { return; } else if (StringUtil.isEmpty(bucketName)) { return; } else if (StringUtil.isEmpty(key)) { return; } if (client.doesObjectExist(bucketName, key)) { client.deleteObject(bucketName, key); } }
From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java
License:MIT License
@Override public void delete(StorageInfo storage, BinaryInfo binary) throws StoreException { logger.debug("={}", storage); logger.debug("?={}", binary); AmazonS3 s3client = getS3Client(binary.getBucketName()); if (!s3client.doesObjectExist(binary.getBucketName(), binary.getFileName())) { logger.info("The Binary has not exsit.bucket={}, binary={}", binary.getBucketName(), binary.getFileName());//from ww w .jav a 2 s . c o m return; } try { s3client.deleteObject(new DeleteObjectRequest(binary.getBucketName(), binary.getFileName())); } catch (AmazonServiceException ase) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.DELETE_FAIL, ase, binary.getFileName()); } catch (AmazonClientException ace) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.DELETE_FAIL, ace, binary.getFileName()); } return; }
From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java
License:MIT License
@Override public BinaryInfo get(StorageInfo storage, BinaryInfo binary) throws StoreException { logger.debug("={}", storage); logger.debug("?={}", binary); AmazonS3 s3client = getS3Client(binary.getBucketName()); try {/* www .j a v a 2 s . com*/ logger.debug("Get an binary"); if (!s3client.doesObjectExist(binary.getBucketName(), binary.getFileName())) { logger.info("The Binary has not exsit.bucket={}, binary={}", binary.getBucketName(), binary.getFileName()); return null; } S3Object s3binary = s3client .getObject(new GetObjectRequest(binary.getBucketName(), binary.getFileName())); binary.setContentType(s3binary.getObjectMetadata().getContentType()); binary.setSize(s3binary.getObjectMetadata().getContentLength()); binary.setUrl(s3client.getUrl(binary.getBucketName(), binary.getFileName()).toString()); logger.debug("Generating pre-signed URL."); URL PresignedUrl = getPresignedUrl(s3client, binary.getBucketName(), binary.getFileName()); binary.setPresignedUrl(PresignedUrl.toString()); logger.debug("Pre-Signed URL = " + PresignedUrl.toString()); } catch (AmazonServiceException ase) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.GET_FAIL, ase, binary.getFileName()); } catch (AmazonClientException ace) { throw new StoreException(HttpStatus.SC_BAD_REQUEST, ErrorClassification.GET_FAIL, ace, binary.getFileName()); } return binary; }
From source file:io.druid.storage.s3.S3Utils.java
License:Apache License
static boolean isObjectInBucketIgnoringPermission(AmazonS3 s3Client, String bucketName, String objectKey) { try {// w ww . j a v a 2 s . co m return s3Client.doesObjectExist(bucketName, objectKey); } catch (AmazonS3Exception e) { if (e.getStatusCode() == 404) { // Object is inaccessible to current user, but does exist. return true; } // Something else has gone wrong throw e; } }
From source file:org.goobi.api.mq.ImportEPHandler.java
private boolean checkIfExistsOnS3(final String _reference) { if (ConfigurationHelper.getInstance().useCustomS3()) { return false; }/*from w w w . j av a 2 s. c o m*/ String bucket; try { XMLConfiguration config = new XMLConfiguration( "/opt/digiverso/goobi/config/plugin_wellcome_editorial_process_creation.xml"); bucket = config.getString("bucket", "wellcomecollection-editorial-photography");// "wellcomecollection-editorial-photography"; log.debug("using bucket " + bucket); } catch (ConfigurationException e) { bucket = "wellcomecollection-editorial-photography"; log.debug("using bucket " + bucket); } String reference = _reference.replaceAll(" |\t", "_"); int refLen = reference.length(); String keyPrefix = reference.substring(refLen - 2, refLen) + "/" + reference + "/"; String key = keyPrefix + reference + ".xml"; AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient(); return s3client.doesObjectExist(bucket, key); }