class ZipSlipAnalyzer implements MaliciousnessAnalyzer {

  @Override
  public MaliciousnessAnalysisResult isMalicious(File _file) {
    MaliciousnessAnalysisResult mal = null;
    final String name = _file.getName();

    try (final InputStream fis = new FileInputStream(_file)) {
      // Analyze
      if (name.endsWith(".zip")
          || name.endsWith(".jar")
          || name.endsWith(".war")
          || name.endsWith(".ear")
          || name.endsWith(".aar")) {
        mal = this.isMalicious(new ZipInputStream(fis), false);
      } else if (name.endsWith(".tar")) {
        mal = this.isMalicious(new TarArchiveInputStream(fis), false);
      } else if (name.endsWith(".tar.gz")) {
        mal =
            this.isMalicious(
                new TarArchiveInputStream(
                    new GzipCompressorInputStream(new BufferedInputStream(fis))),
                false);
      } else {
        log.warn("Cannot analyze [" + _file.toPath().toAbsolutePath() + "]");
      }

      // Log
      if (mal != null) {
        mal.setReason("[" + _file.toPath().toAbsolutePath() + "] " + mal.getReason());
        if (mal.isMalicious()) log.warn(mal.getReason());
        else log.info(mal.getReason());
      }
    } catch (FileNotFoundException fnfe) {
      log.error("File [" + _file.getAbsolutePath() + "] cannot be found");
    } catch (IOException ioe) {
      log.error(
          ioe.getClass().getSimpleName()
              + " when opening ["
              + _file.getAbsolutePath()
              + "]: "
              + ioe.getMessage(),
          ioe);
    }
    return mal;
  }

}