/** Returns the plaintext length from the request and metadata; or -1 if unknown. */ protected final long plaintextLength(PutObjectRequest request, ObjectMetadata metadata) { if (request.getFile() != null) { return request.getFile().length(); } else if (request.getInputStream() != null && metadata.getRawMetadata().get(Headers.CONTENT_LENGTH) != null) { return metadata.getContentLength(); } return -1; }
/** * 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. * @deprecated no longer used and will be removed in the future */ @Deprecated 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 CipherLiteInputStream newS3CipherLiteInputStream( PutObjectRequest req, ContentCryptoMaterial cekMaterial, long plaintextLength) { try { InputStream is = req.getInputStream(); if (req.getFile() != null) is = new RepeatableFileInputStream(req.getFile()); if (plaintextLength > -1) { // S3 allows a single PUT to be no more than 5GB, which // therefore won't exceed the maximum length that can be // encrypted either using any cipher such as CBC or GCM. // 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 CipherLiteInputStream(is, cekMaterial.getCipherLite(), DEFAULT_BUFFER_SIZE); } catch (Exception e) { throw new AmazonClientException("Unable to create cipher input stream: " + e.getMessage(), e); } }
/** * @param plaintextLength the expected total number of bytes of the plaintext; or -1 if not * available. * @deprecated no longer used and will be removed in the future */ @Deprecated 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); } }