Examples of DownloadImpl


Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

                transferProgress), getObjectRequest.getGeneralProgressListener());
        getObjectRequest.setGeneralProgressListener(listenerChain);
        final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectRequest.getBucketName(), getObjectRequest.getKey());

        final StartDownloadLock startDownloadLock = new StartDownloadLock();
        final DownloadImpl download = new DownloadImpl(description, transferProgress, listenerChain, null, stateListener);
        long contentLength = objectMetadata.getContentLength();
        if (getObjectRequest.getRange() != null && getObjectRequest.getRange().length == 2) {
            long startingByte = getObjectRequest.getRange()[0];
            long lastByte     = getObjectRequest.getRange()[1];
            contentLength     = lastByte - startingByte;
        }

        transferProgress.setTotalBytesToTransfer(contentLength);

        Future<?> future = threadPool.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                try {
                    synchronized (startDownloadLock) {
                        if ( !startDownloadLock.downloadReady ) {
                                try {
                                    startDownloadLock.wait();
                                    } catch ( InterruptedException e ) {
                                 throw new AmazonClientException("Couldn't wait for setting future into the monitor");
                             }
                         }
                     }
                    download.setState(TransferState.InProgress);
                    S3Object s3Object = ServiceUtils.retryableDownloadS3ObjectToFile(file, new ServiceUtils.RetryableS3DownloadTask() {
                       
                        @Override
                        public S3Object getS3ObjectStream() {
                            S3Object s3Object = s3.getObject(getObjectRequest);
                            download.setS3Object(s3Object);
                            return s3Object;
                        }
                       
                        @Override
                        public boolean needIntegrityCheck() {
                            // Don't perform the integrity check if the stream data is wrapped
                            // in a decryption stream, or if we're only looking at a range of
                            // the data, since otherwise the checksum won't match up.
                            boolean performIntegrityCheck = true;
                            if (getObjectRequest.getRange() != null) performIntegrityCheck = false;
                            if (s3 instanceof AmazonS3EncryptionClient) performIntegrityCheck = false;
                            return performIntegrityCheck;
                        }
                    });
                   

                    if (s3Object == null) {
                        download.setState(TransferState.Canceled);
                        download.setMonitor(new DownloadMonitor(download, null));
                        return download;
                    }


                    download.setState(TransferState.Completed);
                    return true;
                } catch (Exception e) {
                    // Downloads aren't allowed to move from canceled to failed
                    if (download.getState() != TransferState.Canceled) {
                        download.setState(TransferState.Failed);
                    }
                    throw e;
                }
            }
        });
        download.setMonitor(new DownloadMonitor(download, future));
        synchronized (startDownloadLock) {
            startDownloadLock.downloadReady = true;
            startDownloadLock.notify();
        }
        return download;
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

            getObjectMetadataRequest.setSSECustomerKey(getObjectRequest.getSSECustomerKey());
        }
        final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectMetadataRequest);

        // We still pass the unfiltered listener chain into DownloadImpl
        final DownloadImpl download = new DownloadImpl(description,
                transferProgress, listenerChain, null, stateListener,
                getObjectRequest, file);
        long contentLength = objectMetadata.getContentLength();

        long startingByte = 0;
        long lastByte = contentLength;

        if (getObjectRequest.getRange() != null
                && getObjectRequest.getRange().length == 2) {
            startingByte = getObjectRequest.getRange()[0];
            lastByte = getObjectRequest.getRange()[1];
        }
        if (resumeExistingDownload) {
            if (file.exists()) {
                long numberOfBytesRead = file.length();
                startingByte = startingByte + numberOfBytesRead;
                getObjectRequest.setRange(startingByte, lastByte);
            }
        }
        contentLength = lastByte - startingByte;

        if (contentLength < 0) {
            throw new IllegalArgumentException(
                    "Unable to determine the range for download operation.");
        }
        transferProgress.setTotalBytesToTransfer(contentLength);
        final CountDownLatch latch = new CountDownLatch(1);
        Future<?> future = submitDownloadTask(getObjectRequest, file,
                resumeExistingDownload, latch, download);
        download.setMonitor(new DownloadMonitor(download, future));
        latch.countDown();
        return download;
    }
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

            getObjectMetadataRequest.setSSECustomerKey(getObjectRequest.getSSECustomerKey());
        }
        final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectMetadataRequest);

        // We still pass the unfiltered listener chain into DownloadImpl
        final DownloadImpl download = new DownloadImpl(description,
                transferProgress, listenerChain, null, stateListener,
                getObjectRequest, file);
        long contentLength = objectMetadata.getContentLength();

        long startingByte = 0;
        long lastByte = contentLength;

        if (getObjectRequest.getRange() != null
                && getObjectRequest.getRange().length == 2) {
            startingByte = getObjectRequest.getRange()[0];
            lastByte = getObjectRequest.getRange()[1];
        }
        if (resumeExistingDownload) {
            if (file.exists()) {
                long numberOfBytesRead = file.length();
                startingByte = startingByte + numberOfBytesRead;
                getObjectRequest.setRange(startingByte, lastByte);
            }
        }
        contentLength = lastByte - startingByte;

        if (contentLength < 0) {
            throw new IllegalArgumentException(
                    "Unable to determine the range for download operation.");
        }
        transferProgress.setTotalBytesToTransfer(contentLength);
        final CountDownLatch latch = new CountDownLatch(1);
        Future<?> future = submitDownloadTask(getObjectRequest, file,
                resumeExistingDownload, latch, download);
        download.setMonitor(new DownloadMonitor(download, future));
        latch.countDown();
        return download;
    }
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

        final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectRequest.getBucketName(), getObjectRequest.getKey());

        final StartDownloadLock startDownloadLock = new StartDownloadLock();
        // We still pass the unfiltered listener chain into DownloadImpl
        final DownloadImpl download = new DownloadImpl(description, transferProgress, listenerChain, null, stateListener);
        long contentLength = objectMetadata.getContentLength();
        if (getObjectRequest.getRange() != null && getObjectRequest.getRange().length == 2) {
            long startingByte = getObjectRequest.getRange()[0];
            long lastByte     = getObjectRequest.getRange()[1];
            contentLength     = lastByte - startingByte;
        }

        transferProgress.setTotalBytesToTransfer(contentLength);

        Future<?> future = threadPool.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                try {
                    synchronized (startDownloadLock) {
                        if ( !startDownloadLock.downloadReady ) {
                                try {
                                    startDownloadLock.wait();
                                    } catch ( InterruptedException e ) {
                                 throw new AmazonClientException("Couldn't wait for setting future into the monitor");
                             }
                         }
                     }
                    download.setState(TransferState.InProgress);
                    S3Object s3Object = ServiceUtils.retryableDownloadS3ObjectToFile(file, new ServiceUtils.RetryableS3DownloadTask() {

                        @Override
                        public S3Object getS3ObjectStream() {
                            S3Object s3Object = s3.getObject(getObjectRequest);
                            download.setS3Object(s3Object);
                            return s3Object;
                        }

                        @Override
                        public boolean needIntegrityCheck() {
                            // Don't perform the integrity check if the stream data is wrapped
                            // in a decryption stream, or if we're only looking at a range of
                            // the data, since otherwise the checksum won't match up.
                            boolean performIntegrityCheck = true;
                            if (getObjectRequest.getRange() != null) performIntegrityCheck = false;
                            if (s3 instanceof AmazonS3EncryptionClient) performIntegrityCheck = false;
                            return performIntegrityCheck;
                        }
                    });


                    if (s3Object == null) {
                        download.setState(TransferState.Canceled);
                        download.setMonitor(new DownloadMonitor(download, null));
                        return download;
                    }

                    download.setState(TransferState.Completed);
                    return true;
                } catch (Exception e) {
                    // Downloads aren't allowed to move from canceled to failed
                    if (download.getState() != TransferState.Canceled) {
                        download.setState(TransferState.Failed);
                    }
                    throw e;
                }
            }
        });
        download.setMonitor(new DownloadMonitor(download, future));
        synchronized (startDownloadLock) {
            startDownloadLock.downloadReady = true;
            startDownloadLock.notify();
        }
        return download;
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

        ProgressListenerChain listenerChain = new ProgressListenerChain(new TransferProgressUpdatingListener(
                transferProgress), getObjectRequest.getProgressListener());
        getObjectRequest.setProgressListener(listenerChain);

        final S3Object s3Object = s3.getObject(getObjectRequest);
        final DownloadImpl download = new DownloadImpl(description, transferProgress, listenerChain, s3Object, stateListener);

        // null is returned when constraints aren't met
        if (s3Object == null) {
            download.setState(TransferState.Canceled);
            download.setMonitor(new DownloadMonitor(download, null));
            return download;
        }

        long contentLength = s3Object.getObjectMetadata().getContentLength();
        if (getObjectRequest.getRange() != null && getObjectRequest.getRange().length == 2) {
            long startingByte = getObjectRequest.getRange()[0];
            long lastByte     = getObjectRequest.getRange()[1];
            contentLength     = lastByte - startingByte;
        }
        transferProgress.setTotalBytesToTransfer(contentLength);

        Future<?> future = threadPool.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                try {
                    download.setState(TransferState.InProgress);
                    ServiceUtils.downloadObjectToFile(s3Object, file);
                    download.setState(TransferState.Completed);
                    return true;
                } catch (Exception e) {
                    // Downloads aren't allowed to move from canceled to failed
                    if (download.getState() != TransferState.Canceled) {
                        download.setState(TransferState.Failed);
                    }
                    throw e;
                }
            }
        });
        download.setMonitor(new DownloadMonitor(download, future));

        return download;
    }
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

                transferProgress), getObjectRequest.getProgressListener());
        getObjectRequest.setProgressListener(listenerChain);
        final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectRequest.getBucketName(), getObjectRequest.getKey());
       
        final StartDownloadLock startDownloadLock = new StartDownloadLock();
        final DownloadImpl download = new DownloadImpl(description, transferProgress, listenerChain, null, stateListener);
        long contentLength = objectMetadata.getContentLength();
        if (getObjectRequest.getRange() != null && getObjectRequest.getRange().length == 2) {
            long startingByte = getObjectRequest.getRange()[0];
            long lastByte     = getObjectRequest.getRange()[1];
            contentLength     = lastByte - startingByte;
        }
       
        transferProgress.setTotalBytesToTransfer(contentLength);

        Future<?> future = threadPool.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                try {
                  synchronized (startDownloadLock) {
                    if ( !startDownloadLock.downloadReady ) {
                              try {
                                startDownloadLock.wait();
                                } catch ( InterruptedException e ) {
                                 throw new AmazonClientException("Couldn't wait for setting future into the monitor");
                             }
                     }
                   }
                    download.setState(TransferState.InProgress);
                    final S3Object s3Object = s3.getObject(getObjectRequest);
                   
                    download.setS3Object(s3Object);
 
                     if (s3Object == null) {
                        download.setState(TransferState.Canceled);
                        download.setMonitor(new DownloadMonitor(download, null));
                        return download;
                    }
                    ServiceUtils.downloadObjectToFile(s3Object, file,(getObjectRequest.getRange() == null));
                    download.setState(TransferState.Completed);
                    return true;
                } catch (Exception e) {
                    // Downloads aren't allowed to move from canceled to failed
                    if (download.getState() != TransferState.Canceled) {
                        download.setState(TransferState.Failed);
                    }
                    throw e;
                }
            }
        });
        download.setMonitor(new DownloadMonitor(download, future));
        synchronized (startDownloadLock) {
          startDownloadLock.downloadReady = true;
          startDownloadLock.notify();
        }
        return download;
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

        ProgressListenerChain listenerChain = new ProgressListenerChain(new TransferProgressUpdatingListener(
                transferProgress), getObjectRequest.getProgressListener());
        getObjectRequest.setProgressListener(listenerChain);

        final S3Object s3Object = s3.getObject(getObjectRequest);
        final DownloadImpl download = new DownloadImpl(description, transferProgress, listenerChain, s3Object);

        // null is returned when constraints aren't met
        if (s3Object == null) {
            download.setState(TransferState.Canceled);
            download.setMonitor(new DownloadMonitor(download, null));
            return download;
        }

        long contentLength = s3Object.getObjectMetadata().getContentLength();
        if (getObjectRequest.getRange() != null && getObjectRequest.getRange().length == 2) {
            long startingByte = getObjectRequest.getRange()[0];
            long lastByte     = getObjectRequest.getRange()[1];
            contentLength     = lastByte - startingByte;
        }
        transferProgress.setTotalBytesToTransfer(contentLength);

        Future<?> future = threadPool.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                try {
                    download.setState(TransferState.InProgress);
                    ServiceUtils.downloadObjectToFile(s3Object, file);
                    download.setState(TransferState.Completed);
                    return true;
                } catch (Throwable t) {
                    // Downloads aren't allowed to move from canceled to failed
                    if (download.getState() != TransferState.Canceled) {
                        download.setState(TransferState.Failed);
                    }
                    return false;
                }
            }
        });
        download.setMonitor(new DownloadMonitor(download, future));

        return download;
    }
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

            getObjectMetadataRequest.setSSECustomerKey(getObjectRequest.getSSECustomerKey());
        }
        final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectMetadataRequest);

        // We still pass the unfiltered listener chain into DownloadImpl
        final DownloadImpl download = new DownloadImpl(description,
                transferProgress, listenerChain, null, stateListener,
                getObjectRequest, file);

        long startingByte = 0;
        long lastByte = objectMetadata.getContentLength();

        if (getObjectRequest.getRange() != null
                && getObjectRequest.getRange().length == 2) {
            startingByte = getObjectRequest.getRange()[0];
            lastByte = getObjectRequest.getRange()[1];
        }

        long totalBytesToDownload = lastByte - startingByte;
        transferProgress.setTotalBytesToTransfer(totalBytesToDownload);

        if (resumeExistingDownload) {
            if (file.exists()) {
                long numberOfBytesRead = file.length();
                startingByte = startingByte + numberOfBytesRead;
                getObjectRequest.setRange(startingByte, lastByte);
                transferProgress.updateProgress(Math.min(numberOfBytesRead,
                        totalBytesToDownload));
                totalBytesToDownload = lastByte - startingByte;
            }
        }

        if (totalBytesToDownload < 0) {
            throw new IllegalArgumentException(
                    "Unable to determine the range for download operation.");
        }

        final CountDownLatch latch = new CountDownLatch(1);
        Future<?> future = submitDownloadTask(getObjectRequest, file,
                resumeExistingDownload, latch, download);
        download.setMonitor(new DownloadMonitor(download, future));
        latch.countDown();
        return download;
    }
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

        final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectRequest.getBucketName(), getObjectRequest.getKey());

        final StartDownloadLock startDownloadLock = new StartDownloadLock();
        // We still pass the unfiltered listener chain into DownloadImpl
        final DownloadImpl download = new DownloadImpl(description, transferProgress, listenerChain, null, stateListener);
        long contentLength = objectMetadata.getContentLength();
        if (getObjectRequest.getRange() != null && getObjectRequest.getRange().length == 2) {
            long startingByte = getObjectRequest.getRange()[0];
            long lastByte     = getObjectRequest.getRange()[1];
            contentLength     = lastByte - startingByte;
        }

        transferProgress.setTotalBytesToTransfer(contentLength);

        Future<?> future = threadPool.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                try {
                    synchronized (startDownloadLock) {
                        if ( !startDownloadLock.downloadReady ) {
                                try {
                                    startDownloadLock.wait();
                                    } catch ( InterruptedException e ) {
                                 throw new AmazonClientException("Couldn't wait for setting future into the monitor");
                             }
                         }
                     }
                    download.setState(TransferState.InProgress);
                    S3Object s3Object = ServiceUtils.retryableDownloadS3ObjectToFile(file, new ServiceUtils.RetryableS3DownloadTask() {

                        @Override
                        public S3Object getS3ObjectStream() {
                            S3Object s3Object = s3.getObject(getObjectRequest);
                            download.setS3Object(s3Object);
                            return s3Object;
                        }

                        @Override
                        public boolean needIntegrityCheck() {
                            // Don't perform the integrity check if the stream data is wrapped
                            // in a decryption stream, or if we're only looking at a range of
                            // the data, since otherwise the checksum won't match up.
                            boolean performIntegrityCheck = true;
                            if (getObjectRequest.getRange() != null) performIntegrityCheck = false;
                            if (s3 instanceof AmazonS3EncryptionClient) performIntegrityCheck = false;
                            return performIntegrityCheck;
                        }
                    });


                    if (s3Object == null) {
                        download.setState(TransferState.Canceled);
                        download.setMonitor(new DownloadMonitor(download, null));
                        return download;
                    }

                    download.setState(TransferState.Completed);
                    return true;
                } catch (Exception e) {
                    // Downloads aren't allowed to move from canceled to failed
                    if (download.getState() != TransferState.Canceled) {
                        download.setState(TransferState.Failed);
                    }
                    throw e;
                }
            }
        });
        download.setMonitor(new DownloadMonitor(download, future));
        synchronized (startDownloadLock) {
            startDownloadLock.downloadReady = true;
            startDownloadLock.notify();
        }
        return download;
View Full Code Here

Examples of com.amazonaws.services.s3.transfer.internal.DownloadImpl

            getObjectMetadataRequest.setVersionId(getObjectRequest.getVersionId());
        }
        final ObjectMetadata objectMetadata = s3.getObjectMetadata(getObjectMetadataRequest);

        // We still pass the unfiltered listener chain into DownloadImpl
        final DownloadImpl download = new DownloadImpl(description,
                transferProgress, listenerChain, null, stateListener,
                getObjectRequest, file);

        long startingByte = 0;
        long lastByte = objectMetadata.getContentLength();

        if (getObjectRequest.getRange() != null
                && getObjectRequest.getRange().length == 2) {
            startingByte = getObjectRequest.getRange()[0];
            lastByte = getObjectRequest.getRange()[1];
        }

        long totalBytesToDownload = lastByte - startingByte;
        transferProgress.setTotalBytesToTransfer(totalBytesToDownload);

        if (resumeExistingDownload) {
            if (file.exists()) {
                long numberOfBytesRead = file.length();
                startingByte = startingByte + numberOfBytesRead;
                getObjectRequest.setRange(startingByte, lastByte);
                transferProgress.updateProgress(Math.min(numberOfBytesRead,
                        totalBytesToDownload));
                totalBytesToDownload = lastByte - startingByte;
            }
        }

        if (totalBytesToDownload < 0) {
            throw new IllegalArgumentException(
                    "Unable to determine the range for download operation.");
        }

        final CountDownLatch latch = new CountDownLatch(1);
        Future<?> future = submitDownloadTask(getObjectRequest, file,
                resumeExistingDownload, latch, download);
        download.setMonitor(new DownloadMonitor(download, future));
        latch.countDown();
        return download;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.