code: public static byte[] zip(Map<String, List<String>> namesMap, Map<String, List<byte[]>> contentsMap) throws IOException {
  
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          // Create the ZIP file
          ZipOutputStream out = new ZipOutputStream(baos);
  
          for (String folder : namesMap.keySet()) {
  
              // create the folder
              out.putNextEntry(new ZipEntry(folder + "/"));
  
              List<String> fileNames = namesMap.get(folder);
              List<byte[]> fileContents = contentsMap.get(folder);
  
              for (int i = 0, size = fileNames.size(); i < size; i++) {
                  String name = fileNames.get(i);
                  byte[] content = fileContents.get(i);
  
                  // Add ZIP entry to output stream.
                  ZipEntry entry = new ZipEntry(folder + "/" + name);
                  entry.setSize(content.length);
                  out.putNextEntry(entry);
                  out.write(content);
                  // Complete the entry
                  out.closeEntry();
              }
          }
          out.close();
          return baos.toByteArray();
      }
docs: Zip files
  
  @param namesMap map of files to zip , each entry is the name of the folder where these files are added
  @param contentsMap map of file contents
  @return zip byte content
  @throws java.io.IOException IOException