/** * @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); } }
@Test public void testRead() throws IOException { File tmp = File.createTempFile("test" + new Date(), null); try { FileWriter writer = new FileWriter(tmp); writer.write("content"); writer.close(); RepeatableFileInputStream rfis = new RepeatableFileInputStream(tmp); try { ByteArrayOutputStream read = new ByteArrayOutputStream(); int curr = -1; while ((curr = rfis.read()) != -1) { read.write(curr); } read.flush(); assertEquals(rfis.getWrappedInputStream().read(), -1); assertEquals(read.toString(), "content"); assertSame(rfis.getFile(), tmp); } finally { rfis.close(); } } finally { tmp.delete(); } }
InputStream originalInputStream = request.getInputStream(); if (request.getFile() != null) { originalInputStream = new InputSubstream(new RepeatableFileInputStream( request.getFile()), request.getFileOffset(), request.getPartSize(), request.isLastPart());
outputStream.close(); RepeatableFileInputStream repeatableFileInputStream = new RepeatableFileInputStream( tempFile); InputSubstream in = new InputSubstream(repeatableFileInputStream, 10, 10, true);
private InputSubstream newInputSubstream(File file, long startingPosition, long length) { InputSubstream in = null; try { in = new InputSubstream(new RepeatableFileInputStream(file), startingPosition, length, true); } catch (FileNotFoundException e) { throw new AmazonClientException("Unable to find file '" + file.getAbsolutePath() + "'", e); } return in; }
protected InputStream getInputStream(File source, TransferProgress progress) throws FileNotFoundException { if (progress == null) { return new RepeatableFileInputStream(source); } else { return new TransferProgressFileInputStream(source, progress); } }
} else if (uploadPartRequest.getFile() != null) { try { inputStream = new InputSubstream(new RepeatableFileInputStream( uploadPartRequest.getFile()), uploadPartRequest.getFileOffset(), partSize, true);
input = new RepeatableFileInputStream(file); } catch (final FileNotFoundException fnfe) { throw new AmazonClientException("Unable to find file to upload", fnfe);
/** * @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); } }
InputStream originalInputStream = request.getInputStream(); if (request.getFile() != null) { originalInputStream = new InputSubstream(new RepeatableFileInputStream( request.getFile()), request.getFileOffset(), request.getPartSize(), request.isLastPart());
} else if (uploadPartRequest.getFile() != null) { try { inputStream = new InputSubstream(new RepeatableFileInputStream( uploadPartRequest.getFile()), uploadPartRequest.getFileOffset(), partSize, true);
input = new RepeatableFileInputStream(file); } catch (final FileNotFoundException fnfe) { throw new AmazonClientException("Unable to find file to upload", fnfe);