Examples of TransferProgressImpl


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

        }

        /* This is the hook for adding additional progress listeners */
        ProgressListenerChain additionalProgressListenerChain = new ProgressListenerChain();

        TransferProgressImpl transferProgress = new TransferProgressImpl();
        /*
         * Bind additional progress listeners to this
         * MultipleFileTransferProgressUpdatingListener to receive
         * ByteTransferred events from each single-file upload implementation.
         */
        ProgressListener multipleFileTransferProgressListener = new MultipleFileTransferProgressUpdatingListener(
                transferProgress, additionalProgressListenerChain);

        List<UploadImpl> uploads = new LinkedList<UploadImpl>();
        MultipleFileUploadImpl multipleFileUpload = new MultipleFileUploadImpl("Uploading etc", transferProgress, additionalProgressListenerChain, virtualDirectoryKeyPrefix, bucketName, uploads);
        multipleFileUpload.setMonitor(new MultipleFileTransferMonitor(multipleFileUpload, uploads));

        final AllDownloadsQueuedLock allTransfersQueuedLock = new AllDownloadsQueuedLock();
        MultipleFileTransferStateChangeListener multipleFileTransferStateChangeListener = new MultipleFileTransferStateChangeListener(
                allTransfersQueuedLock, multipleFileUpload);

        if ( files == null || files.isEmpty()) {
            multipleFileUpload.setState(TransferState.Completed);
        }

        /*
         * If the absolute path for the common/base directory does NOT end in a
         * separator (which is the case for anything but root directories), then
         * we know there's still a separator between the base directory and the
         * rest of the file's path, so we increment the starting position by one.
         */
        int startingPosition = directory.getAbsolutePath().length();
        if (!(directory.getAbsolutePath().endsWith(File.separator))) startingPosition++;

        long totalSize = 0;
        for (File f : files) {
            //Check, if file, since only files can be uploaded.
            if (f.isFile()) {
                totalSize += f.length();

                String key = f.getAbsolutePath().substring(startingPosition).replaceAll("\\\\", "/");

                ObjectMetadata metadata=new ObjectMetadata();

                // Invoke the callback if it's present.
                // The callback allows the user to customize the metadata for each file being uploaded.
                if (metadataProvider != null) {
                    metadataProvider.provideObjectMetadata(f, metadata);
                }

                // All the single-file uploads share the same
                // MultipleFileTransferProgressUpdatingListener and
                // MultipleFileTransferStateChangeListener
                uploads.add((UploadImpl) upload(
                        new PutObjectRequest(bucketName,
                                virtualDirectoryKeyPrefix + key, f)
                                .withMetadata(metadata)
                                .withGeneralProgressListener(
                                        multipleFileTransferProgressListener),
                        multipleFileTransferStateChangeListener));
            }
        }

        transferProgress.setTotalBytesToTransfer(totalSize);

        // Notify all state changes waiting for the uploads to all be queued
        // to wake up and continue
        synchronized (allTransfersQueuedLock) {
            allTransfersQueuedLock.allQueued = true;
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.