- java.lang.Object
-
- io.helidon.config.FileSourceHelper
-
public final class FileSourceHelper extends Object
Utilities for file-related source classes.- See Also:
FileConfigSource,FileOverrideSource,DirectoryConfigSource
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileSourceHelper.DataAndDigestData and digest of a file.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<byte[]>digest(Path path)Returns an MD5 digest of the specified file or null if the file cannot be read.static booleanisModified(Path filePath, byte[] digest)Check if a file on the file system is changed, as compared to the digest provided.static booleanisModified(Path filePath, Instant stamp)Check if a file on the file system is changed based on its last modification timestamp.static Optional<Instant>lastModifiedTime(Path path)Returns the last modified time of the given file or directory.static Optional<FileSourceHelper.DataAndDigest>readDataAndDigest(Path filePath)Read data and its digest in the same go.static StringsafeReadContent(Path path)Reads the content of the specified file.
-
-
-
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 filedigest- digest of the file- Returns:
trueif the file exists and has the same digest,falseotherwise
-
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 filestamp- last modification stamp- Returns:
trueif the file exists and has the same last modification timestamp,falseotherwise
-
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
-
-