List of usage examples for com.amazonaws.services.s3.model PutObjectRequest getKey
public String getKey()
From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java
License:Apache License
/** * Puts an object./*from www .j av a 2 s .co m*/ */ @Override public Upload upload(PutObjectRequest putObjectRequest, TransferManager transferManager) throws AmazonServiceException, AmazonClientException { LOGGER.debug("upload(): putObjectRequest.getBucketName() = " + putObjectRequest.getBucketName() + ", putObjectRequest.getKey() = " + putObjectRequest.getKey()); putObject(putObjectRequest, (AmazonS3Client) transferManager.getAmazonS3Client()); long contentLength = putObjectRequest.getFile().length(); TransferProgress progress = new TransferProgress(); progress.setTotalBytesToTransfer(contentLength); progress.updateProgress(contentLength); UploadImpl upload = new UploadImpl(null, progress, null, null); upload.setState(TransferState.Completed); return upload; }
From source file:org.finra.herd.dao.impl.MockS3OperationsImpl.java
License:Apache License
/** * {@inheritDoc}/* w w w . j a v a 2s .com*/ * <p/> * This implementation creates a new bucket if the bucket does not already exist. */ @Override public PutObjectResult putObject(PutObjectRequest putObjectRequest, AmazonS3 s3Client) { LOGGER.debug("putObject(): putObjectRequest.getBucketName() = " + putObjectRequest.getBucketName() + ", putObjectRequest.getKey() = " + putObjectRequest.getKey()); String s3BucketName = putObjectRequest.getBucketName(); InputStream inputStream = putObjectRequest.getInputStream(); ObjectMetadata metadata = putObjectRequest.getMetadata(); if (metadata == null) { metadata = new ObjectMetadata(); } File file = putObjectRequest.getFile(); if (file != null) { try { inputStream = new FileInputStream(file); metadata.setContentLength(file.length()); } catch (FileNotFoundException e) { throw new IllegalArgumentException("File not found " + file, e); } } String s3ObjectKey = putObjectRequest.getKey(); String s3ObjectVersion = MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED.equals(putObjectRequest.getBucketName()) ? UUID.randomUUID().toString() : null; String s3ObjectKeyVersion = s3ObjectKey + (s3ObjectVersion != null ? s3ObjectVersion : ""); byte[] s3ObjectData; try { s3ObjectData = IOUtils.toByteArray(inputStream); metadata.setContentLength(s3ObjectData.length); } catch (IOException e) { throw new IllegalArgumentException("Error converting input stream into byte array", e); } finally { try { inputStream.close(); } catch (IOException e) { LOGGER.error("Error closing stream " + inputStream, e); } } // Update the Last-Modified header value. This value not being set causes NullPointerException in S3Dao download related unit tests. metadata.setLastModified(new Date()); MockS3Bucket mockS3Bucket = getOrCreateBucket(s3BucketName); MockS3Object mockS3Object = new MockS3Object(); mockS3Object.setKey(s3ObjectKey); mockS3Object.setVersion(s3ObjectVersion); mockS3Object.setData(s3ObjectData); mockS3Object.setObjectMetadata(metadata); if (putObjectRequest.getTagging() != null) { mockS3Object.setTags(putObjectRequest.getTagging().getTagSet()); } mockS3Bucket.getObjects().put(s3ObjectKey, mockS3Object); mockS3Bucket.getVersions().put(s3ObjectKeyVersion, mockS3Object); return new PutObjectResult(); }
From source file:org.finra.herd.dao.impl.MockS3OperationsImpl.java
License:Apache License
@Override public Upload upload(PutObjectRequest putObjectRequest, TransferManager transferManager) { LOGGER.debug("upload(): putObjectRequest.getBucketName() = " + putObjectRequest.getBucketName() + ", putObjectRequest.getKey() = " + putObjectRequest.getKey()); putObject(putObjectRequest, transferManager.getAmazonS3Client()); long contentLength = putObjectRequest.getFile().length(); TransferProgress progress = new TransferProgress(); progress.setTotalBytesToTransfer(contentLength); progress.updateProgress(contentLength); UploadImpl upload = new UploadImpl(null, progress, null, null); upload.setState(TransferState.Completed); return upload; }
From source file:org.geowebcache.s3.S3Ops.java
License:Open Source License
public void putObject(PutObjectRequest putObjectRequest) throws StorageException { try {/*from w w w . ja v a2s . c o m*/ conn.putObject(putObjectRequest); } catch (RuntimeException e) { throw new StorageException("Error storing " + putObjectRequest.getKey(), e); } }