Interface FileHasher

  • Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface FileHasher
    A function to convert a Path to a hash code used to check if the file content is changed. This is called by DirectoryWatcher after checking that the path exists and is not a directory. Therefore this hasher can generally assume that those two things are true.

    By default, this hasher may throw an IOException, which will be treated as a `null` hash by the watcher, meaning the associated event will be ignored. If you want to handle that exception you can catch/rethrow it.

    • Field Detail

      • DEFAULT_FILE_HASHER

        static final FileHasher DEFAULT_FILE_HASHER
        The default file hasher instance, which uses Murmur3.
      • LAST_MODIFIED_TIME

        static final FileHasher LAST_MODIFIED_TIME
        A file hasher that returns the last modified time provided by the OS.

        This only works reliably on certain file systems and JDKs that support at least millisecond-level precision.

    • Method Detail

      • hash

        FileHash hash​(java.nio.file.Path path)
               throws java.io.IOException
        Throws:
        java.io.IOException