class ZipUtils {

  public static ArrayByteSource zipInMemory(List<? extends BeanByteSource> sources) {
    long instantMillis = System.currentTimeMillis();
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      try (ZipOutputStream out = new ZipOutputStream(baos)) {
        for (BeanByteSource source : sources) {
          ZipEntry entry = new ZipEntry(
              source.getFileName()
                  .orElseThrow(() -> new IllegalArgumentException("ByteSource must have a name in order to be zipped")));
          entry.setTime(instantMillis);
          out.putNextEntry(entry);
          source.copyTo(out);
          out.closeEntry();
        }
      }
      return ArrayByteSource.ofUnsafe(baos.toByteArray());
    } catch (IOException ex) {
      throw new UncheckedIOException(ex);
    }
  }

  private  ZipUtils();

}