Class Handle

java.lang.Object
org.apache.sshd.sftp.server.Handle
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, AttributeRepository, AttributeStore
Direct Known Subclasses:
DirectoryHandle, FileHandle

public abstract class Handle extends Object implements Channel, AttributeStore
  • Field Details

  • Constructor Details

  • Method Details

    • getSubsystem

      protected SftpSubsystem getSubsystem()
    • signalHandleOpening

      protected void signalHandleOpening() throws IOException
      Throws:
      IOException
    • signalHandleOpen

      protected void signalHandleOpen() throws IOException
      Throws:
      IOException
    • getFile

      public Path getFile()
    • getFileHandle

      public String 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 interface AttributeRepository
      Returns:
      Current number of user-defined attributes stored in the repository
    • getAttribute

      public <T> T getAttribute(AttributeRepository.AttributeKey<T> key)
      Description copied from interface: AttributeRepository
      Returns the value of the user-defined attribute.
      Specified by:
      getAttribute in interface AttributeRepository
      Type Parameters:
      T - The generic attribute type
      Parameters:
      key - The key of the attribute; must not be null.
      Returns:
      null if there is no value associated with the specified key
    • attributeKeys

      public Collection<AttributeRepository.AttributeKey<?>> attributeKeys()
      Specified by:
      attributeKeys in interface AttributeRepository
      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 to null), attempts to compute its value using the given mapping function and enters it into this map unless null.
      Specified by:
      computeAttributeIfAbsent in interface AttributeStore
      Type Parameters:
      T - The generic attribute type
      Parameters:
      key - The key of the attribute; must not be null.
      resolver - The (never null) mapping function to use if value not already mapped. If returns null 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

      public <T> T setAttribute(AttributeRepository.AttributeKey<T> key, T value)
      Description copied from interface: AttributeStore
      Sets a user-defined attribute.
      Specified by:
      setAttribute in interface AttributeStore
      Type Parameters:
      T - The generic attribute type
      Parameters:
      key - The key of the attribute; must not be null.
      value - The value of the attribute; must not be null.
      Returns:
      The old value of the attribute; null if it is new.
    • removeAttribute

      public <T> T removeAttribute(AttributeRepository.AttributeKey<T> key)
      Description copied from interface: AttributeStore
      Removes the user-defined attribute
      Specified by:
      removeAttribute in interface AttributeStore
      Type Parameters:
      T - The generic attribute type
      Parameters:
      key - The key of the attribute; must not be null.
      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 interface AttributeStore
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface Channel
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • safe

      protected static String safe(String handle)
      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