List of usage examples for com.amazonaws.event ProgressEventType REQUEST_BYTE_TRANSFER_EVENT
ProgressEventType REQUEST_BYTE_TRANSFER_EVENT
To view the source code for com.amazonaws.event ProgressEventType REQUEST_BYTE_TRANSFER_EVENT.
Click Source Link
From source file:com.github.rholder.esthree.command.GetMultipart.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;/*w w w .j a v a 2 s .c om*/ while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); if (progressListener != null) { progress.updateProgress(n); progressListener .progressChanged(new ProgressEvent(ProgressEventType.REQUEST_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; }
From source file:io.dockstore.common.FileProvisioning.java
License:Apache License
public void provisionOutputFile(FileInfo file, String cwlOutputPath) { File sourceFile = new File(cwlOutputPath); long inputSize = sourceFile.length(); if (file.getUrl().startsWith("s3://")) { AmazonS3 s3Client = FileProvisioning.getAmazonS3Client(config); String trimmedPath = file.getUrl().replace("s3://", ""); List<String> splitPathList = Lists.newArrayList(trimmedPath.split("/")); String bucketName = splitPathList.remove(0); PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, Joiner.on("/").join(splitPathList), sourceFile);//from www . j a v a 2s .c o m putObjectRequest.setGeneralProgressListener(new ProgressListener() { ProgressPrinter printer = new ProgressPrinter(); long runningTotal = 0; @Override public void progressChanged(ProgressEvent progressEvent) { if (progressEvent.getEventType() == ProgressEventType.REQUEST_BYTE_TRANSFER_EVENT) { runningTotal += progressEvent.getBytesTransferred(); } printer.handleProgress(runningTotal, inputSize); } }); try { s3Client.putObject(putObjectRequest); } finally { System.out.println(); } } else { try { FileSystemManager fsManager; // trigger a copy from the URL to a local file path that's a UUID to avoid collision fsManager = VFS.getManager(); // check for a local file path FileObject dest = fsManager.resolveFile(file.getUrl()); FileObject src = fsManager.resolveFile(sourceFile.getAbsolutePath()); copyFromInputStreamToOutputStream(src.getContent().getInputStream(), inputSize, dest.getContent().getOutputStream()); } catch (IOException e) { throw new RuntimeException("Could not provision output files", e); } } }