private UploadResult uploadInParts ( ) throws Exception { boolean isUsingEncryption = s3 instanceof AmazonS3Encryption ; long optimalPartSize = getOptimalPartSize ( isUsingEncryption ) ; try { if ( multipartUploadId == null ) { multipartUploadId = initiateMultipartUpload ( origReq , isUsingEncryption ) ; } UploadPartRequestFactory requestFactory = new UploadPartRequestFactory ( origReq , multipartUploadId , optimalPartSize ) ; if ( TransferManagerUtils . isUploadParallelizable ( origReq , isUsingEncryption ) ) { captureUploadStateIfPossible ( ) ; uploadPartsInParallel ( requestFactory , multipartUploadId ) ; return null ; } else { return uploadPartsInSeries ( requestFactory ) ; } } catch ( Exception e ) { publishProgress ( listener , ProgressEventType . TRANSFER_FAILED_EVENT ) ; performAbortMultipartUpload ( ) ; throw e ; } finally { if ( origReq . getInputStream ( ) != null ) { try { origReq . getInputStream ( ) . close ( ) ; } catch ( Exception e ) { log . warn ( "Unable to cleanly close input stream: " + e . getMessage ( ) , e ) ; } } } }
Uploads the request in multiple chunks submitting each upload chunk task to the thread pool and recording its corresponding Future object as well as the multipart upload id .