private void downloadInParallel ( int partCount ) throws Exception { if ( lastFullyMergedPartNumber == null ) { lastFullyMergedPartNumber = 0 ; } if ( lastFullyMergedPartPosition == null ) { lastFullyMergedPartPosition = 0L ; } long previousPartLength = 0L ; long filePositionToWrite = lastFullyMergedPartPosition ; createParentDirectoryIfNecessary ( dstfile ) ; truncateDestinationFileIfNecessary ( ) ; if ( ! FileLocks . lock ( dstfile ) ) { throw new FileLockException ( "Fail to lock " + dstfile ) ; } for ( int i = lastFullyMergedPartNumber + 1 ; i <= partCount ; i ++ ) { filePositionToWrite += previousPartLength ; GetObjectRequest getPartRequest = new GetObjectRequest ( req . getBucketName ( ) , req . getKey ( ) , req . getVersionId ( ) ) . withUnmodifiedSinceConstraint ( req . getUnmodifiedSinceConstraint ( ) ) . withModifiedSinceConstraint ( req . getModifiedSinceConstraint ( ) ) . withResponseHeaders ( req . getResponseHeaders ( ) ) . withSSECustomerKey ( req . getSSECustomerKey ( ) ) . withGeneralProgressListener ( req . getGeneralProgressListener ( ) ) ; getPartRequest . setMatchingETagConstraints ( req . getMatchingETagConstraints ( ) ) ; getPartRequest . setNonmatchingETagConstraints ( req . getNonmatchingETagConstraints ( ) ) ; getPartRequest . setRequesterPays ( req . isRequesterPays ( ) ) ; // Update the part number getPartRequest . setPartNumber ( i ) ; futures . add ( executor . submit ( new DownloadS3ObjectCallable ( serviceCall ( getPartRequest ) , dstfile , filePositionToWrite ) ) ) ; previousPartLength = ServiceUtils . getPartSize ( req , s3 , i ) ; } Future < File > future = executor . submit ( new CompleteMultipartDownload ( futures , dstfile , download , ++ lastFullyMergedPartNumber ) ) ; ( ( DownloadMonitor ) download . getMonitor ( ) ) . setFuture ( future ) ; }
Downloads each part of the object into the different parts of the destination file in parallel .