Class ScpLocation

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, MutableUserHolder, UsernameHolder

    public class ScpLocation
    extends java.lang.Object
    implements MutableUserHolder, java.io.Serializable, java.lang.Cloneable
    Represents a local or remote SCP location in the format user@host:path for a remote path and a simple path for a local one. If user is omitted for a remote path then current user is used.
    See Also:
    Serialized Form
    • Field Detail

      • USERNAME_PART_SEPARATOR

        public static final char USERNAME_PART_SEPARATOR
        See Also:
        Constant Field Values
      • host

        private java.lang.String host
      • username

        private java.lang.String username
      • path

        private java.lang.String path
    • Constructor Detail

      • ScpLocation

        public ScpLocation()
      • ScpLocation

        public ScpLocation​(java.lang.String locSpec)
        Parameters:
        locSpec - The location specification - ignored if null/empty
        Throws:
        java.lang.IllegalArgumentException - if invalid specification
        See Also:
        update(String, ScpLocation)
    • Method Detail

      • getHost

        public java.lang.String getHost()
      • setHost

        public void setHost​(java.lang.String host)
      • isLocal

        public boolean isLocal()
      • getUsername

        public java.lang.String getUsername()
        Specified by:
        getUsername in interface UsernameHolder
        Returns:
        The attached username - may be null/empty if holder not yet initialized
      • resolveUsername

        public java.lang.String resolveUsername()
        Resolves the effective username to use for a remote location. If username not set then uses the current username
        Returns:
        The resolved username
        See Also:
        getUsername(), OsUtils.getCurrentUser()
      • getPath

        public java.lang.String getPath()
      • setPath

        public void setPath​(java.lang.String path)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • clone

        public ScpLocation clone()
        Overrides:
        clone in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • parse

        public static ScpLocation parse​(java.lang.String locSpec)
        Parses a local or remote SCP location in the format user@host:path
        Parameters:
        locSpec - The location specification - ignored if null/empty
        Returns:
        The ScpLocation or null if no specification provider
        Throws:
        java.lang.IllegalArgumentException - if invalid specification
        See Also:
        update(String, ScpLocation)
      • update

        public static <L extends ScpLocation> L update​(java.lang.String locSpec,
                                                       L location)
        Parses a local or remote SCP location in the format user@host:path
        Type Parameters:
        L - Type of ScpLocation being updated
        Parameters:
        locSpec - The location specification - ignored if null/empty
        location - The ScpLocation to update - never null
        Returns:
        The updated location (unless no specification)
        Throws:
        java.lang.IllegalArgumentException - if invalid specification