@Override public int available() throws IOException { abortIfNeeded(); return fis.available(); }
/** * @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(); } }
@Override public int read() throws IOException { int read = super.read(); if (read != -1) position++; triggerError(); return read; }
InputStream originalInputStream = request.getInputStream(); if (request.getFile() != null) { originalInputStream = new InputSubstream(new RepeatableFileInputStream( request.getFile()), request.getFileOffset(), request.getPartSize(), request.isLastPart());
@Override public int read(byte[] b, int off, int len) throws IOException { int read = super.read(b, off, len); position += read; triggerError(); return read; }
@Override public long skip(long n) throws IOException { abortIfNeeded(); long skipped = fis.skip(n); bytesReadPastMarkPoint += skipped; return skipped; }
outputStream.close(); RepeatableFileInputStream repeatableFileInputStream = new RepeatableFileInputStream( tempFile); InputSubstream in = new InputSubstream(repeatableFileInputStream, 10, 10, true);
@Override public int read() throws IOException { int b = super.read(); if (b != -1) { progress.notify(new byte[] { (byte) b }, 1); } return b; }
@Override public void close() throws IOException { fis.close(); abortIfNeeded(); }
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; }
@Override public int read(byte b[]) throws IOException { int length = super.read(b); if (length != -1) { progress.notify(b, length); } return length; }
@Override public int read() throws IOException { abortIfNeeded(); int byteRead = fis.read(); if (byteRead != -1) { bytesReadPastMarkPoint++; return byteRead; } else { return -1; } }
protected InputStream getInputStream(File source, TransferProgress progress) throws FileNotFoundException { if (progress == null) { return new RepeatableFileInputStream(source); } else { return new TransferProgressFileInputStream(source, progress); } }
@Override public int read(byte b[], int off, int len) throws IOException { int count = super.read(b, off, len); if (count == -1) { return count; } if (off == 0) { progress.notify(b, count); } else { byte[] bytes = new byte[len]; System.arraycopy(b, off, bytes, 0, count); progress.notify(bytes, count); } return count; } }
@Override public int read(byte[] arg0, int arg1, int arg2) throws IOException { abortIfNeeded(); int count = fis.read(arg0, arg1, arg2); bytesReadPastMarkPoint += count; return count; }
} else if (uploadPartRequest.getFile() != null) { try { inputStream = new InputSubstream(new RepeatableFileInputStream( uploadPartRequest.getFile()), uploadPartRequest.getFileOffset(), partSize, true);
@Override public void mark(int readlimit) { abortIfNeeded(); this.markPoint += bytesReadPastMarkPoint; this.bytesReadPastMarkPoint = 0; if (log.isDebugEnabled()) { log.debug("Input stream marked at " + this.markPoint + " bytes"); } }
input = new RepeatableFileInputStream(file); } catch (final FileNotFoundException fnfe) { throw new AmazonClientException("Unable to find file to upload", fnfe);
/** * Resets the input stream to the last mark point, or the beginning of the * stream if there is no mark point, by creating a new FileInputStream based * on the underlying file. * * @throws IOException * when the FileInputStream cannot be re-created. */ @Override public void reset() throws IOException { this.fis.close(); abortIfNeeded(); this.fis = new FileInputStream(file); long skipped = 0; long toSkip = markPoint; while (toSkip > 0) { skipped = this.fis.skip(toSkip); toSkip -= skipped; } if (log.isDebugEnabled()) { log.debug("Reset to mark point " + markPoint + " after returning " + bytesReadPastMarkPoint + " bytes"); } this.bytesReadPastMarkPoint = 0; }