Package org.apache.sshd.common.util.io
Class ModifiableFileWatcher
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.common.util.io.ModifiableFileWatcher
-
- Direct Known Subclasses:
ClientIdentityFileWatcher,ConfigFileHostEntryResolver,FileWatcherKeyPairResourceLoader
public class ModifiableFileWatcher extends AbstractLoggingBean
Watches over changes for a file and re-loads them if file has changed - including if file is deleted or (re-)created- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description protected LinkOption[]optionsstatic Set<PosixFilePermission>STRICTLY_PROHIBITED_FILE_PERMISSIONTheSetofPosixFilePermissionnot allowed if strict permissions are enforced on key files-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description ModifiableFileWatcher(Path file)ModifiableFileWatcher(Path file, LinkOption... options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckReloadRequired()booleanexists()PathgetPath()FileTimelastModified()voidresetReloadAttributes()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 timelongsize()PathResourcetoPathResource()PathResourcetoPathResource(OpenOption... options)StringtoString()voidupdateReloadAttributes()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 AbstractMap.SimpleImmutableEntry<String,Object>validateStrictConfigFilePermissions(Path path, LinkOption... options)Checks if a path has strict permissions
-
-
-
Field Detail
-
STRICTLY_PROHIBITED_FILE_PERMISSION
public static final Set<PosixFilePermission> STRICTLY_PROHIBITED_FILE_PERMISSION
TheSetofPosixFilePermissionnot allowed if strict permissions are enforced on key files
-
options
protected final LinkOption[] options
-
-
Constructor Detail
-
ModifiableFileWatcher
public ModifiableFileWatcher(Path file)
-
ModifiableFileWatcher
public ModifiableFileWatcher(Path file, LinkOption... options)
-
-
Method Detail
-
exists
public final boolean exists() throws IOException- Throws:
IOException
-
size
public final long size() throws IOException- Throws:
IOException
-
lastModified
public final FileTime lastModified() throws IOException
- Throws:
IOException
-
checkReloadRequired
public boolean checkReloadRequired() throws IOException- Returns:
trueif the watched file has probably been changed- Throws:
IOException- If failed to query file data
-
resetReloadAttributes
public 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
-
updateReloadAttributes
public void updateReloadAttributes() throws IOExceptionMay 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. If the file does not exist then the attributes are reset to an "unknown" state.- Throws:
IOException- If failed to access the file (if exists)- See Also:
resetReloadAttributes()
-
toPathResource
public PathResource toPathResource()
-
toPathResource
public PathResource toPathResource(OpenOption... options)
-
validateStrictConfigFilePermissions
public static AbstractMap.SimpleImmutableEntry<String,Object> validateStrictConfigFilePermissions(Path path, LinkOption... options) throws 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.
- Parameters:
path- ThePathto be checked - ignored ifnullor does not existoptions- TheLinkOptions to use to query the file's permissions- Returns:
- The violated permission as
AbstractMap.SimpleImmutableEntrywhere key is a loggable message and value is the offending object - e.g.,PosixFilePermissionorStringfor owner. Return value isnullif no violations detected - Throws:
IOException- If failed to retrieve the permissions- See Also:
STRICTLY_PROHIBITED_FILE_PERMISSION
-
-
-