use of com.amazonaws.internal.ResettableInputStream in project aws-sdk-android by aws-amplify.
the class S3CryptoModuleBase method newS3CipherLiteInputStream.
private CipherLiteInputStream newS3CipherLiteInputStream(AbstractPutObjectRequest req, ContentCryptoMaterial cekMaterial, long plaintextLength) {
final File fileOrig = req.getFile();
final InputStream isOrig = req.getInputStream();
InputStream isCurr = null;
try {
if (fileOrig == null) {
// When input is a FileInputStream, this wrapping enables
// unlimited mark-and-reset
isCurr = isOrig == null ? null : ReleasableInputStream.wrap(isOrig);
} else {
isCurr = new ResettableInputStream(fileOrig);
}
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.
isCurr = new LengthCheckInputStream(isCurr, plaintextLength, EXCLUDE_SKIPPED_BYTES);
}
final CipherLite cipherLite = cekMaterial.getCipherLite();
if (cipherLite.markSupported()) {
return new CipherLiteInputStream(isCurr, cipherLite, DEFAULT_BUFFER_SIZE);
} else {
return new RenewableCipherLiteInputStream(isCurr, cipherLite, DEFAULT_BUFFER_SIZE);
}
} catch (final Exception e) {
cleanupDataSource(req, fileOrig, isOrig, isCurr, log);
throw new AmazonClientException("Unable to create cipher input stream", e);
}
}
use of com.amazonaws.internal.ResettableInputStream in project aws-sdk-android by aws-amplify.
the class S3CryptoModuleBase method newMultipartS3CipherInputStream.
protected final CipherLiteInputStream newMultipartS3CipherInputStream(UploadPartRequest req, CipherLite cipherLite) {
final File fileOrig = req.getFile();
final InputStream isOrig = req.getInputStream();
InputStream isCurr = null;
try {
if (fileOrig == null) {
if (isOrig == null) {
throw new IllegalArgumentException("A File or InputStream must be specified when uploading part");
}
isCurr = isOrig;
} else {
isCurr = new ResettableInputStream(fileOrig);
}
isCurr = new InputSubstream(isCurr, req.getFileOffset(), req.getPartSize(), req.isLastPart());
return cipherLite.markSupported() ? new CipherLiteInputStream(isCurr, cipherLite, DEFAULT_BUFFER_SIZE, IS_MULTI_PART, req.isLastPart()) : new RenewableCipherLiteInputStream(isCurr, cipherLite, DEFAULT_BUFFER_SIZE, IS_MULTI_PART, req.isLastPart());
} catch (final Exception e) {
cleanupDataSource(req, fileOrig, isOrig, isCurr, log);
throw new AmazonClientException("Unable to create cipher input stream", e);
}
}
use of com.amazonaws.internal.ResettableInputStream in project sirius-biz by scireum.
the class Storage method updateFile.
/**
* Updates the given file using the given data.
*
* @param file the S3 file to update
* @param data the data to store
* @param filename the original filename to save
*/
public void updateFile(@Nonnull StoredObject file, @Nonnull File data, @Nullable String filename) {
try {
try (InputStream in = new ResettableInputStream(data)) {
String md5 = calculateMd5(data);
updateFile(file, in, filename, md5, data.length());
}
} catch (Exception e) {
throw Exceptions.handle().to(LOG).error(e).withSystemErrorMessage("Cannot upload the file: %s (%s) - %s (%s)", file, filename).handle();
}
}
Aggregations