Top Description Fields Constructors Methods
org.apache.sshd.common.util.io

public Class ModifiableFileWatcher

extends AbstractLoggingBean
Class Inheritance
Known Direct Subclasses
org.apache.sshd.client.config.hosts.ConfigFileHostEntryResolver, org.apache.sshd.client.config.keys.ClientIdentityFileWatcher, org.apache.sshd.common.config.keys.loader.FileWatcherKeyPairResourceLoader
Imports
java.io.IOException, java.nio.file.Files, .LinkOption, .OpenOption, .Path, java.nio.file.attribute.BasicFileAttributes, .FileTime, .PosixFilePermission, java.util.AbstractMap.SimpleImmutableEntry, .Collection, .Collections, .EnumSet, .HashSet, .Objects, .Set, java.util.concurrent.atomic.AtomicReference, org.apache.sshd.common.util.GenericUtils, .OsUtils, org.apache.sshd.common.util.io.resource.PathResource, org.apache.sshd.common.util.logging.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

Modifier and TypeField and Description
private final Path
private final AtomicReference<FileSnapshot>
protected final LinkOption[]
public static final Set<PosixFilePermission>
STRICTLY_PROHIBITED_FILE_PERMISSION

The Set of PosixFilePermission not allowed if strict permissions are enforced on key files

Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
log

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the watched file has probably been changed
checkReloadRequired
()

public final boolean
public final Path

Returns:

The watched Path
getPath
()

public final FileTime
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

public final long
size()

public PathResource
public PathResource
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public 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.

public static AbstractMap.SimpleImmutableEntry<String, Object>

Returns:

The violated permission as 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 detected
validateStrictConfigFilePermissions
(Path
The Path to be checked - ignored if null or does not exist
path
,
LinkOption...
The LinkOptions to use to query the file's permissions
options
)

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.
Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
debugdebugdebugdebugdebugerrorerrorerrorerrorerrorgetSimplifiedLoggerinfoinfowarnwarnwarnwarnwarnwarnwarnwarn

Field Detail

fileback to summary
private final Path file
metadataback to summary
private final AtomicReference<FileSnapshot> metadata
optionsback to summary
protected final LinkOption[] options
STRICTLY_PROHIBITED_FILE_PERMISSIONback to summary
public static final Set<PosixFilePermission> STRICTLY_PROHIBITED_FILE_PERMISSION

The Set of PosixFilePermission not allowed if strict permissions are enforced on key files

Constructor Detail

ModifiableFileWatcherback to summary
public ModifiableFileWatcher(Path file)
ModifiableFileWatcherback to summary
public ModifiableFileWatcher(Path file, LinkOption... options)

Method Detail

checkReloadRequiredback to summary
public boolean checkReloadRequired() throws IOException
Returns:boolean

true if the watched file has probably been changed

Exceptions
IOException:
If failed to query file data
existsback to summary
public final boolean exists() throws IOException
getPathback to summary
public final Path getPath()
Returns:Path

The watched Path

lastModifiedback to summary
public final FileTime lastModified() throws IOException
resetReloadAttributesback to summary
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

sizeback to summary
public final long size() throws IOException
toPathResourceback to summary
public PathResource toPathResource()
toPathResourceback to summary
public PathResource toPathResource(OpenOption... options)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateReloadAttributesback to summary
public void updateReloadAttributes() throws IOException

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. If the file does not exist then the attributes are reset to an "unknown" state.

Exceptions
IOException:
If failed to access the file (if exists)
See Also
resetReloadAttributes()
validateStrictConfigFilePermissionsback to summary
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:Path

The Path to be checked - ignored if null or does not exist

options:LinkOption[]

The LinkOptions to use to query the file's permissions

Returns:AbstractMap.SimpleImmutableEntry<String, Object>

The violated permission as 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 detected

Exceptions
IOException:
If failed to retrieve the permissions
See Also
STRICTLY_PROHIBITED_FILE_PERMISSION