class FileSourceHelper {

    @SuppressWarnings("StatementWithEmptyBody")
    public static Optional<byte[]> digest(Path path) {
        MessageDigest digest = digest();

        try (DigestInputStream dis = new DigestInputStream(Files.newInputStream(path), digest)) {
            byte[] buffer = new byte[FILE_BUFFER_SIZE];
            while (dis.read(buffer) != -1) {
                // just discard - we are only interested in the digest information
            }
            return Optional.of(digest.digest());
        } catch (FileNotFoundException e) {
            return Optional.empty();
        } catch (IOException e) {
            throw new ConfigException("Failed to calculate digest for file: " + path, e);
        }
    }

    private  FileSourceHelper();

}