class UnzipUtility {

  public static void unzip(InputStream zipStream, Path destDirectory) throws IOException {
    if (!destDirectory.toFile().isDirectory()) {
      throw new IOException(
          String.format(
              "Output directory does not exist or is not a direcotry: %s", destDirectory));
    }
    try (ZipInputStream zipIn = new ZipInputStream(zipStream)) {
      for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn.getNextEntry()) {
        // entry may start with '/', so we do a little magic to ensure it is applied relatively
        // against destDirectory
        Path outputPath =
            validatePath(
                new File(destDirectory.toFile(), new File(entry.getName()).getPath()).toPath(),
                destDirectory);
        if (entry.isDirectory()) {
          // Make the directory, including parent dirs.
          if (!outputPath.toFile().exists()) {
            if (!outputPath.toFile().mkdirs()) {
              throw new IOException("Unable to make directory " + outputPath);
            }
          }
        } else {
          // Make sure parent directories exist, in case the zip does not contain dir entries
          createParentDirectories(outputPath);
          // Extract the file.
          extractFile(zipIn, outputPath);
        }
        zipIn.closeEntry();
      }
    }
  }

  private  UnzipUtility();

}