List of usage examples for com.amazonaws.event ProgressEventType RESPONSE_BYTE_TRANSFER_EVENT
ProgressEventType RESPONSE_BYTE_TRANSFER_EVENT
To view the source code for com.amazonaws.event ProgressEventType RESPONSE_BYTE_TRANSFER_EVENT.
Click Source Link
From source file:com.github.rholder.esthree.command.Get.java
License:Apache License
public MessageDigest copyAndHash(InputStream input, long totalBytes, Progress progress) throws IOException, CloneNotSupportedException { // clone the current digest, such that it remains unchanged in this method MessageDigest computedDigest = (MessageDigest) currentDigest.clone(); byte[] buffer = new byte[DEFAULT_BUF_SIZE]; long count = 0; int n;//from ww w . jav a 2 s.c o m while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); if (progressListener != null) { progress.updateProgress(n); progressListener .progressChanged(new ProgressEvent(ProgressEventType.RESPONSE_BYTE_TRANSFER_EVENT, n)); } computedDigest.update(buffer, 0, n); count += n; } // verify that at least this many bytes were read if (totalBytes != count) { throw new IOException( String.format("%d bytes downloaded instead of expected %d bytes", count, totalBytes)); } return computedDigest; }