Class FileSourceHelper

    • Method Detail

      • lastModifiedTime

        public static Optional<Instant> lastModifiedTime​(Path path)
        Returns the last modified time of the given file or directory.
        Parameters:
        path - a file or directory
        Returns:
        the last modified time
      • safeReadContent

        public static String safeReadContent​(Path path)
        Reads the content of the specified file.

        The file is locked before the reading and the lock is released immediately after the reading.

        An expected encoding is UTF-8.

        Parameters:
        path - a path to the file
        Returns:
        a content of the file
      • digest

        public static Optional<byte[]> digest​(Path path)
        Returns an MD5 digest of the specified file or null if the file cannot be read.

        The file is locked before the reading and the lock is released immediately after the reading.

        Parameters:
        path - a path to the file
        Returns:
        an MD5 digest of the file or null if the file cannot be read
      • isModified

        public static boolean isModified​(Path filePath,
                                         byte[] digest)
        Check if a file on the file system is changed, as compared to the digest provided.
        Parameters:
        filePath - path of the file
        digest - digest of the file
        Returns:
        true if the file exists and has the same digest, false otherwise
      • isModified

        public static boolean isModified​(Path filePath,
                                         Instant stamp)
        Check if a file on the file system is changed based on its last modification timestamp.
        Parameters:
        filePath - path of the file
        stamp - last modification stamp
        Returns:
        true if the file exists and has the same last modification timestamp, false otherwise
      • readDataAndDigest

        public static Optional<FileSourceHelper.DataAndDigest> readDataAndDigest​(Path filePath)
        Read data and its digest in the same go.
        Parameters:
        filePath - path to load data from
        Returns:
        data and its digest, or empty if file does not exist