virtualDirectoryKeyPrefix = "";
} else if ( !virtualDirectoryKeyPrefix.endsWith("/") ) {
virtualDirectoryKeyPrefix = virtualDirectoryKeyPrefix + "/";
}
TransferProgressImpl transferProgress = new TransferProgressImpl();
ProgressListener listener = new TransferProgressUpdatingListener(transferProgress);
List<UploadImpl> uploads = new LinkedList<UploadImpl>();
MultipleFileUploadImpl multipleFileUpload = new MultipleFileUploadImpl("Uploading etc", transferProgress, null, virtualDirectoryKeyPrefix, bucketName, uploads);
multipleFileUpload.setMonitor(new MultipleFileTransferMonitor(multipleFileUpload, uploads));
final AllDownloadsQueuedLock allTransfersQueuedLock = new AllDownloadsQueuedLock();
MultipleFileTransferStateChangeListener stateChangeListener = new MultipleFileTransferStateChangeListener(
allTransfersQueuedLock, multipleFileUpload);
long totalSize = 0;
List<File> files = new LinkedList<File>();
listFiles(directory, files, includeSubdirectories);
if (files.isEmpty()) {
multipleFileUpload.setState(TransferState.Completed);
}
for (File f : files) {
totalSize += f.length();
String key = f.getAbsolutePath().substring(directory.getAbsolutePath().length() + 1)
.replaceAll("\\\\", "/");
uploads.add((UploadImpl) upload(
new PutObjectRequest(bucketName, virtualDirectoryKeyPrefix + key, f).withProgressListener(listener),
stateChangeListener));
}
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;