ZipSourceFileHelper { protected static void validateZip(ZipFile zipFile, int maxEntries, long maxSize) { if (zipFile.stream().limit(maxEntries + 1).count() > maxEntries) { throw new CustomWebApplicationException("Too many entries in the zip", HttpStatus.SC_BAD_REQUEST); } final Optional<Long> uncompressedSize = zipFile.stream().map(z -> z.getSize()).reduce(Long::sum); uncompressedSize.ifPresent(s -> { if (s > maxSize) { throw new CustomWebApplicationException("Zip contents too large", HttpStatus.SC_BAD_REQUEST); } }); } private  ZipSourceFileHelper(); static SourceFiles sourceFilesFromInputStream(InputStream payload, DescriptorLanguage.FileType fileType); static String addLeadingSlashIfNecessary(final String name);  }
@Test public void validateZip() throws IOException { ZipFile smartSeqZipFile = new ZipFile(new File(SMART_SEQ_ZIP_PATH)); try { ZipSourceFileHelper.validateZip(smartSeqZipFile, 1, 1); fail("Exepcted validate to throw error"); } catch (Exception ex) { } try { ZipSourceFileHelper.validateZip(smartSeqZipFile, 1, 100); fail("Exepcted validate to throw error"); } catch (Exception ex) { } ZipSourceFileHelper.validateZip(smartSeqZipFile, 100, 100_000); }