Source:
public void downloadMultipleExperimentsArchive(HttpServletResponse response, @RequestParam(value = "accession", defaultValue = "") List<String> accessions) throws IOException { List<Experiment> experiments = new ArrayList<Experiment>(); for (String accession : accessions) { try { experiments.add(experimentTrader.getPublicExperiment(accession)); } catch (Exception e) { System.out.println("Experiment accession is not valid: " + accession); } } if (experiments.size() >= 1) { String archiveName = experiments.size() + "-experiment-files.zip"; response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + archiveName); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/zip"); ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream()); for (Experiment experiment : experiments) { ImmutableList<Path> paths = ImmutableList.<Path>builder() .addAll(experimentFileLocationService.getFilePathsForArchive( experiment.getAccession(), ExperimentFileType.QUANTIFICATION_FILTERED)) .addAll(experimentFileLocationService.getFilePathsForArchive( experiment.getAccession(), ExperimentFileType.QUANTIFICATION_RAW)) .addAll(experimentFileLocationService.getFilePathsForArchive( experiment.getAccession(), ExperimentFileType.NORMALISED)) .add(experimentFileLocationService.getFilePath( experiment.getAccession(), ExperimentFileType.SDRF)) .build(); for (Path path : paths) { File file = path.toFile(); zipOutputStream.putNextEntry(new ZipEntry(experiment.getAccession() + "/" + file.getName())); FileInputStream fileInputStream = new FileInputStream(file); IOUtils.copy(fileInputStream, zipOutputStream); fileInputStream.close(); zipOutputStream.closeEntry(); } } zipOutputStream.close(); } }

Target:
public void downloadMultipleExperimentsArchive(HttpServletResponse response, @RequestParam(value = "accession", defaultValue = "") List<String> accessions) throws IOException { List<Experiment> experiments = new ArrayList<>(); for (String accession : accessions) { try { experiments.add(experimentTrader.getPublicExperiment(accession)); } catch (Exception e) { LOGGER.debug("Invalid experiment accession: {}", accession); } } if (!experiments.isEmpty()) { String archiveName = experiments.size() + "-experiment-files.zip"; response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + archiveName); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/zip"); ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream()); for (Experiment experiment : experiments) { ImmutableList<Path> paths = ImmutableList.<Path>builder() .addAll(experimentFileLocationService.getFilePathsForArchive( experiment.getAccession(), ExperimentFileType.QUANTIFICATION_FILTERED)) .addAll(experimentFileLocationService.getFilePathsForArchive( experiment.getAccession(), ExperimentFileType.QUANTIFICATION_RAW)) .addAll(experimentFileLocationService.getFilePathsForArchive( experiment.getAccession(), ExperimentFileType.NORMALISED)) .add(experimentFileLocationService.getFilePath( experiment.getAccession(), ExperimentFileType.SDRF)) .build(); for (Path path : paths) { File file = path.toFile(); zipOutputStream.putNextEntry(new ZipEntry(experiment.getAccession() + "/" + file.getName())); FileInputStream fileInputStream = new FileInputStream(file); IOUtils.copy(fileInputStream, zipOutputStream); fileInputStream.close(); zipOutputStream.closeEntry(); } } zipOutputStream.close(); } }