private static Map processChecksum()

in src/main/java/com/epam/digital/data/platform/registry/regulation/validation/cli/utils/FileChecksumGenerator.java [99:134]


  private static Map<String, String> processChecksum(File file, CommandFileOption fileOption) {
    var checksum = new HashMap<String, String>();
    try {
      Path relativizePath;
      var messageDigest = MessageDigest.getInstance(ALGORITHM);
      var filePath = file.toPath();
      var directoryPathFromRelativize =
          Objects.isNull(filePath.getParent()) ? filePath : filePath.getParent();
      if (file.isDirectory()) {
        var filePathsFromDirectory = getFilePathsFromDirectory(filePath);
        for (Path path : filePathsFromDirectory) {
          messageDigest.update(Files.readAllBytes(path));
          if (CommandFileOption.FILE_DETAILED.equals(fileOption)) {
            relativizePath = directoryPathFromRelativize.relativize(path);
            checksum.put(relativizePath.toString(),
                hexBinaryAdapter.marshal(messageDigest.digest()));
            messageDigest.reset();
          }
        }
        if (CommandFileOption.FILE.equals(fileOption)) {
          relativizePath = directoryPathFromRelativize.relativize(filePath);
          checksum.put(relativizePath.toString(), hexBinaryAdapter.marshal(messageDigest.digest()));
        }
      } else {
        var filePathFromRelativize =
            Objects.isNull(directoryPathFromRelativize.getParent()) ? directoryPathFromRelativize
                : directoryPathFromRelativize.getParent();
        relativizePath = filePathFromRelativize.relativize(filePath);
        messageDigest.update(Files.readAllBytes(file.toPath()));
        checksum.put(relativizePath.toString(), hexBinaryAdapter.marshal(messageDigest.digest()));
      }
    } catch (Exception e) {
      throw new FileProcessingException("Error while generating checksums", e);
    }
    return checksum;
  }