//TODO: change API of storage service and remove explicit cast
if (!(storageService instanceof FileStorageService)) {
throw new IllegalStateException("Please supply the FileStorageService instance");
}
final FileStorageService fileStorageService = (FileStorageService) storageService;
final ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
final Iterable<DashboardReader.FileLine> filesToDownload = getFilesToDownload(request);
if (request.experimentId != null) {
addExperimentCSVFile(request, zos);
addAttachments(request, zos);
}
long totalSizeInBytes = 0;
for (DashboardReader.FileLine fileLine : filesToDownload) {
totalSizeInBytes = totalSizeInBytes + fileLine.columns.sizeInBytes;
}
for (final DashboardReader.FileLine file : filesToDownload) {
final NodePath nodePath = new NodePath(file.contentId);
pushFileToZip(zos, file.columns.name, new InputStreamProvider() {
@Override
public S3ObjectInputStream get() {
return fileStorageService.getAsStream(nodePath);
}
});
}
zos.close();
//Set cookie to satisfy AJAX downloader at the client: