code: public static byte[] zip(List<String> fileNames, List<byte[]> fileContents) throws IOException {
  
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          // Create the ZIP file
          ZipOutputStream out = new ZipOutputStream(baos);
  
          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(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 fileNames list of file names to zip
  @param fileContents list of file contents
  @return zip byte content
  @throws java.io.IOException IOException