public UploadPartRequestFactory(PutObjectRequest origReq, String uploadId, long optimalPartSize) { this.origReq = origReq; this.uploadId = uploadId; this.optimalPartSize = optimalPartSize; this.bucketName = origReq.getBucketName(); this.key = origReq.getKey(); this.file = TransferManagerUtils.getRequestFile(origReq); this.remainingBytes = TransferManagerUtils.getContentLength(origReq); this.sseCustomerKey = origReq.getSSECustomerKey(); this.totalNumberOfParts = (int) Math.ceil((double) this.remainingBytes / this.optimalPartSize); if (origReq.getInputStream() != null) { wrappedStream = ReleasableInputStream.wrap(origReq.getInputStream()); } }
/** * Returns the size of the data in this request, otherwise -1 if the content * length is unknown. * * @param putObjectRequest * The request to check. * * @return The size of the data in this request, otherwise -1 if the size of * the data is unknown. */ public static long getContentLength(PutObjectRequest putObjectRequest) { File file = getRequestFile(putObjectRequest); if (file != null) return file.length(); if (putObjectRequest.getInputStream() != null) { if (putObjectRequest.getMetadata().getContentLength() > 0) { return putObjectRequest.getMetadata().getContentLength(); } } return -1; }
throw e; } finally { if (origReq.getInputStream() != null) { try {origReq.getInputStream().close(); } catch (Exception e) { log.warn("Unable to cleanly close input stream: " + e.getMessage(), e);
private PutObjectResult putObjectUsingMetadata(PutObjectRequest req) { ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req); // Wraps the object data with a cipher input stream final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); PutObjectRequest wrappedReq = wrapWithCipher(req, cekMaterial); // Update the metadata req.setMetadata(updateMetadataWithContentCryptoMaterial( req.getMetadata(), req.getFile(), cekMaterial)); // Put the encrypted object into S3 try { return s3.putObject(wrappedReq); } finally { cleanupDataSource(req, fileOrig, isOrig, wrappedReq.getInputStream(), log); } }
PutObjectRequest putObjectRequest) { final File fileOrig = putObjectRequest.getFile(); final InputStream isOrig = putObjectRequest.getInputStream(); final PutObjectRequest putInstFileRequest = putObjectRequest.clone() .withFile(null) } finally { cleanupDataSource(putObjectRequest, fileOrig, isOrig, req.getInputStream(), log);
rejectNull(putObjectRequest, "The PutObjectRequest parameter must be specified when uploading an object"); final File file = putObjectRequest.getFile(); final InputStream isOrig = putObjectRequest.getInputStream(); final String bucketName = putObjectRequest.getBucketName(); final String key = putObjectRequest.getKey();
/** * Returns the content length of the unencrypted data in a PutObjectRequest, * or -1 if the original content-length isn't known. * * @param request The request to examine. * @param metadata The metadata for the request. * @return The content length of the unencrypted data in the request, or -1 * if it isn't known. */ private static long getUnencryptedContentLength(PutObjectRequest request, ObjectMetadata metadata) { if (request.getFile() != null) { return request.getFile().length(); } else if (request.getInputStream() != null && metadata.getRawMetadataValue(Headers.CONTENT_LENGTH) != null) { return metadata.getContentLength(); } return -1; }
/** * Returns the size of the data in this request, otherwise -1 if the content * length is unknown. * * @param putObjectRequest The request to check. * @return The size of the data in this request, otherwise -1 if the size of * the data is unknown. */ public static long getContentLength(PutObjectRequest putObjectRequest) { File file = getRequestFile(putObjectRequest); if (file != null) return file.length(); if (putObjectRequest.getInputStream() != null) { if (putObjectRequest.getMetadata().getContentLength() > 0) { return putObjectRequest.getMetadata().getContentLength(); } } return -1; }
private PutObjectResult putObjectUsingMetadata(PutObjectRequest req) { final ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req); // Wraps the object data with a cipher input stream final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); final PutObjectRequest wrappedReq = wrapWithCipher(req, cekMaterial); // Update the metadata req.setMetadata(updateMetadataWithContentCryptoMaterial( req.getMetadata(), req.getFile(), cekMaterial)); // Put the encrypted object into S3 try { return s3.putObject(wrappedReq); } finally { cleanupDataSource(req, fileOrig, isOrig, wrappedReq.getInputStream(), log); } }
/** * @param plaintextLength the expected total number of bytes of the * plaintext; or -1 if not available. */ private static InputStream getEncryptedInputStream( PutObjectRequest request, CipherFactory cipherFactory, long plaintextLength) { try { InputStream is = request.getInputStream(); if (request.getFile() != null) { // Historically file takes precedence over the original input // stream is = new RepeatableFileInputStream(request.getFile()); } if (plaintextLength > -1) { // This ensures the plain-text read from the underlying data // stream has the same length as the expected total is = new LengthCheckInputStream(is, plaintextLength, EXCLUDE_SKIPPED_BYTES); } return new RepeatableCipherInputStream(is, cipherFactory); } catch (Exception e) { throw new AmazonClientException("Unable to create cipher input stream: " + e.getMessage(), e); } }
throw e; } finally { if (putObjectRequest.getInputStream() != null) { try { putObjectRequest.getInputStream().close(); } catch (Exception e) { log.warn("Unable to cleanly close input stream: " + e.getMessage(), e);
@Test public void testUploadFromByteArray() throws IOException { EasyMock.reset(mockS3); EasyMock.expect(mockS3.getRegion()).andReturn(Region.US_Standard); Capture<PutObjectRequest> por = new Capture<PutObjectRequest>(); EasyMock.expect(mockS3.putObject(EasyMock.capture(por))).andReturn(null); EasyMock.replay(mockS3); mapper.getS3ClientCache().useClient(mockS3); S3Link link = mapper.createS3Link(bucket, key); link.uploadFrom("Test".getBytes(StringUtils.UTF8)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); InputStream is = por.getValue().getInputStream(); int currByte = -1; while ((currByte = is.read()) != -1) { bos.write(currByte); } assertArrayEquals(bos.toByteArray(), "Test".getBytes(StringUtils.UTF8)); EasyMock.verify(); }
PutObjectRequest putObjectRequest) { final File fileOrig = putObjectRequest.getFile(); final InputStream isOrig = putObjectRequest.getInputStream(); final PutObjectRequest putInstFileRequest = putObjectRequest.clone() .withFile(null) } finally { cleanupDataSource(putObjectRequest, fileOrig, isOrig, req.getInputStream(), log);
if (putObjectRequest.getInputStream() != null) { request = new UploadPartRequest() .withBucketName(bucketName) .withUploadId(uploadId) .withInputStream( new InputSubstream(putObjectRequest.getInputStream(), 0, partSize, isLastPart)) .withPartNumber(partNumber++)
final String key = putObjectRequest.getKey(); ObjectMetadata metadata = putObjectRequest.getMetadata(); InputStream input = putObjectRequest.getInputStream();
public PutObjectResult putObject(PutObjectRequest putRequest) throws AmazonClientException { // If we have an inputstream, modify the putRequest with a file of known size instead if (putRequest.getFile() == null && putRequest.getInputStream() != null) { File cachedFile = cacheLocally(putRequest.getInputStream(), putRequest.getKey()); putRequest.setInputStream(null); putRequest.setFile(cachedFile); PutObjectResult result = super.putObject(putRequest); cachedFile.delete(); return result; } return super.putObject(putRequest); }
public UploadPartRequestFactory(PutObjectRequest origReq, String uploadId, long optimalPartSize) { this.origReq = origReq; this.uploadId = uploadId; this.optimalPartSize = optimalPartSize; this.bucketName = origReq.getBucketName(); this.key = origReq.getKey(); this.file = TransferManagerUtils.getRequestFile(origReq); this.remainingBytes = TransferManagerUtils.getContentLength(origReq); this.sseCustomerKey = origReq.getSSECustomerKey(); this.totalNumberOfParts = (int) Math.ceil((double) this.remainingBytes / this.optimalPartSize); if (origReq.getInputStream() != null) { wrappedStream = ReleasableInputStream.wrap(origReq.getInputStream()); } }
private PutObjectResult putObjectUsingMetadata(PutObjectRequest req) { final ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req); // Wraps the object data with a cipher input stream final File fileOrig = req.getFile(); final InputStream isOrig = req.getInputStream(); final PutObjectRequest wrappedReq = wrapWithCipher(req, cekMaterial); // Update the metadata req.setMetadata(updateMetadataWithContentCryptoMaterial( req.getMetadata(), req.getFile(), cekMaterial)); // Put the encrypted object into S3 try { return s3.putObject(wrappedReq); } finally { cleanupDataSource(req, fileOrig, isOrig, wrappedReq.getInputStream(), log); } }
@Override public PutObjectResult putObject(PutObjectRequest putRequest) throws AmazonClientException { String bucketName = putRequest.getBucketName(); String key = putRequest.getKey(); InputStream inputStream = putRequest.getInputStream(); if (inputStream == null) { File inFile = putRequest.getFile(); inputStream = getInputStream(inFile); } return putObject(bucketName, key, inputStream, putRequest.getMetadata()); }
assertNull(from.getCannedAcl()); assertEquals(file, from.getFile()); assertNull(from.getInputStream()); assertNull(from.getRedirectLocation()); assertNull(from.getStorageClass()); assertSame(System.in, to.getInputStream());