private static void handleZip()

in TransformCore/src/main/java/com/facebook/ads/injkit/ZipRecursionHandler.java [44:76]


  private static void handleZip(File file, ZipEntryConsumer zipEntryConsumer)
      throws IOException, AnnotationProcessingException {
    try (ZipFile inputZipFile = new ZipFile(file)) {

      // pathsInZip protects against zips having more than one file with the same path.
      // It is weird, but it can happen, and ZipOutputStream doesn't work.
      Set<String> pathsInZip = new HashSet<>();
      Enumeration<? extends ZipEntry> entries = inputZipFile.entries();
      while (entries.hasMoreElements()) {
        ZipEntry nextEntry = entries.nextElement();

        if (pathsInZip.contains(nextEntry.getName())) {
          continue;
        }

        pathsInZip.add(nextEntry.getName());

        try (InputStream fileInput = inputZipFile.getInputStream(nextEntry);
            ClassFileDetectorStream cfds =
                new ClassFileDetectorStream(nextEntry.getName(), fileInput)) {
          try {
            zipEntryConsumer.consumeZipEntry(nextEntry.getName(), cfds.isClass(), cfds);
          } catch (IOException e) {
            throw new IOException(
                String.format(Locale.US, "Failed to process zip '%s'", file.getAbsolutePath()), e);
          } catch (AnnotationProcessingException e) {
            throw new AnnotationProcessingException(
                String.format(Locale.US, "Failed to process zip '%s'", file.getAbsolutePath()), e);
          }
        }
      }
    }
  }