Class FileSourceHelper

java.lang.Object
io.helidon.config.FileSourceHelper

public final class FileSourceHelper extends Object
Utilities for file-related source classes.
See Also:
  • Field Details

    • PROPERTY_DIGEST_ALGORITHM

      public static final String PROPERTY_DIGEST_ALGORITHM
      Property used for specifying the algorithm that will be used to generate digest of a config file.
      See Also:
  • Method Details

    • 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. If MD5 is not available, SHA-256 will be used instead. Alternatively, a digest algorithm can be specified using "io.helidon.config.file.digest.algorithm" system property.

      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