Package org.apache.sshd.sftp.server
Class Handle
java.lang.Object
org.apache.sshd.sftp.server.Handle
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,AttributeRepository
,AttributeStore
- Direct Known Subclasses:
DirectoryHandle
,FileHandle
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<AttributeRepository.AttributeKey<?>, Object> private final AtomicBoolean
private final Path
private final String
private final SftpSubsystem
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Handle
(SftpSubsystem subsystem, Path file, String handle) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Removes all currently stored user-defined attributesvoid
close()
<T> T
computeAttributeIfAbsent
(AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>, ? extends T> resolver) If the specified key is not already associated with a value (or is mapped tonull
), attempts to compute its value using the given mapping function and enters it into this map unlessnull
.<T> T
Returns the value of the user-defined attribute.int
getFile()
Retrieves the raw opaque file handle, which may contain characters not safe for printing.protected SftpSubsystem
boolean
isOpen()
<T> T
Removes the user-defined attributeprotected static String
Converts a file handle, which may contain non-printable characters, to a hex representation of its bytes, which is safe to write to logs or exception messages.<T> T
setAttribute
(AttributeRepository.AttributeKey<T> key, T value) Sets a user-defined attribute.protected void
protected void
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sshd.common.AttributeRepository
resolveAttribute
-
Field Details
-
sftpSubsystem
-
closed
-
file
-
handle
-
attributes
-
-
Constructor Details
-
Handle
-
-
Method Details
-
getSubsystem
-
signalHandleOpening
- Throws:
IOException
-
signalHandleOpen
- Throws:
IOException
-
getFile
-
getFileHandle
Retrieves the raw opaque file handle, which may contain characters not safe for printing.- Returns:
- the raw file handle
-
getAttributesCount
public int getAttributesCount()- Specified by:
getAttributesCount
in interfaceAttributeRepository
- Returns:
- Current number of user-defined attributes stored in the repository
-
getAttribute
Description copied from interface:AttributeRepository
Returns the value of the user-defined attribute.- Specified by:
getAttribute
in interfaceAttributeRepository
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.- Returns:
null
if there is no value associated with the specified key
-
attributeKeys
- Specified by:
attributeKeys
in interfaceAttributeRepository
- Returns:
- A
Collection
snapshot of all the currently registered attributes in the repository
-
computeAttributeIfAbsent
public <T> T computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>, ? extends T> resolver) Description copied from interface:AttributeStore
If the specified key is not already associated with a value (or is mapped tonull
), attempts to compute its value using the given mapping function and enters it into this map unlessnull
.- Specified by:
computeAttributeIfAbsent
in interfaceAttributeStore
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.resolver
- The (nevernull
) mapping function to use if value not already mapped. If returnsnull
then value is not mapped to the provided key.- Returns:
- The resolved value -
null
if value not mapped and resolver did not return a non-null
value for it
-
setAttribute
Description copied from interface:AttributeStore
Sets a user-defined attribute.- Specified by:
setAttribute
in interfaceAttributeStore
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.value
- The value of the attribute; must not benull
.- Returns:
- The old value of the attribute;
null
if it is new.
-
removeAttribute
Description copied from interface:AttributeStore
Removes the user-defined attribute- Specified by:
removeAttribute
in interfaceAttributeStore
- Type Parameters:
T
- The generic attribute type- Parameters:
key
- The key of the attribute; must not benull
.- Returns:
- The removed value;
null
if no previous value
-
clearAttributes
public void clearAttributes()Description copied from interface:AttributeStore
Removes all currently stored user-defined attributes- Specified by:
clearAttributes
in interfaceAttributeStore
-
isOpen
public boolean isOpen() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
toString
-
safe
Converts a file handle, which may contain non-printable characters, to a hex representation of its bytes, which is safe to write to logs or exception messages.For historical reasons, Apache MINA sshd represents file handles as strings internally.
- Parameters:
handle
- to convert- Returns:
- the printable handle string
-