public class ModifiableFileWatcher extends AbstractLoggingBean
Modifier and Type | Field and Description |
---|---|
private java.nio.file.Path |
file |
private java.util.concurrent.atomic.AtomicBoolean |
lastExisted |
private java.util.concurrent.atomic.AtomicLong |
lastModified |
private java.util.concurrent.atomic.AtomicLong |
lastSize |
protected java.nio.file.LinkOption[] |
options |
static java.util.Set<java.nio.file.attribute.PosixFilePermission> |
STRICTLY_PROHIBITED_FILE_PERMISSION
The
Set of PosixFilePermission not allowed if strict permissions are enforced on key files |
log
Constructor and Description |
---|
ModifiableFileWatcher(java.nio.file.Path file) |
ModifiableFileWatcher(java.nio.file.Path file,
java.nio.file.LinkOption... options) |
Modifier and Type | Method and Description |
---|---|
boolean |
checkReloadRequired() |
boolean |
exists() |
java.nio.file.Path |
getPath() |
java.nio.file.attribute.FileTime |
lastModified() |
void |
resetReloadAttributes()
Resets the state attributes used to detect changes to the initial construction values - i.e., file assumed not to
exist and no known size of modify time
|
long |
size() |
PathResource |
toPathResource() |
PathResource |
toPathResource(java.nio.file.OpenOption... options) |
java.lang.String |
toString() |
void |
updateReloadAttributes()
May be called to refresh the state attributes used to detect changes e.g., file existence, size and last-modified
time once re-loading is successfully completed.
|
static java.util.AbstractMap.SimpleImmutableEntry<java.lang.String,java.lang.Object> |
validateStrictConfigFilePermissions(java.nio.file.Path path,
java.nio.file.LinkOption... options)
Checks if a path has strict permissions
|
getSimplifiedLogger
public static final java.util.Set<java.nio.file.attribute.PosixFilePermission> STRICTLY_PROHIBITED_FILE_PERMISSION
Set
of PosixFilePermission
not allowed if strict permissions are enforced on key filesprotected final java.nio.file.LinkOption[] options
private final java.nio.file.Path file
private final java.util.concurrent.atomic.AtomicBoolean lastExisted
private final java.util.concurrent.atomic.AtomicLong lastSize
private final java.util.concurrent.atomic.AtomicLong lastModified
public ModifiableFileWatcher(java.nio.file.Path file)
public ModifiableFileWatcher(java.nio.file.Path file, java.nio.file.LinkOption... options)
public final java.nio.file.Path getPath()
Path
public final boolean exists() throws java.io.IOException
java.io.IOException
public final long size() throws java.io.IOException
java.io.IOException
public final java.nio.file.attribute.FileTime lastModified() throws java.io.IOException
java.io.IOException
public boolean checkReloadRequired() throws java.io.IOException
true
if the watched file has probably been changedjava.io.IOException
- If failed to query file datapublic void resetReloadAttributes()
public void updateReloadAttributes() throws java.io.IOException
java.io.IOException
- If failed to access the file (if exists)resetReloadAttributes()
public PathResource toPathResource()
public PathResource toPathResource(java.nio.file.OpenOption... options)
public java.lang.String toString()
toString
in class java.lang.Object
public static java.util.AbstractMap.SimpleImmutableEntry<java.lang.String,java.lang.Object> validateStrictConfigFilePermissions(java.nio.file.Path path, java.nio.file.LinkOption... options) throws java.io.IOException
Checks if a path has strict permissions
(For Unix
) The path may not have group or others write permissions
The path must be owned by current user.
(For Unix
) The path may be owned by root.
path
- The Path
to be checked - ignored if null
or does not existoptions
- The LinkOption
s to use to query the file's permissionsAbstractMap.SimpleImmutableEntry
where key is a loggable message and
value is the offending object - e.g., PosixFilePermission
or String
for
owner. Return value is null
if no violations detectedjava.io.IOException
- If failed to retrieve the permissionsSTRICTLY_PROHIBITED_FILE_PERMISSION