Package org.apache.sshd.scp.common
Class ScpLocation
- java.lang.Object
-
- org.apache.sshd.scp.common.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" or "scp://[user@]host[:port][/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 Summary
Fields Modifier and Type Field Description private java.lang.String
host
static char
HOST_PART_SEPARATOR
private java.lang.String
path
private int
port
static java.lang.String
SCHEME
private static long
serialVersionUID
private java.lang.String
username
static char
USERNAME_PART_SEPARATOR
-
Constructor Summary
Constructors Constructor Description ScpLocation()
ScpLocation(java.lang.String locSpec)
ScpLocation(java.lang.String username, java.lang.String host, int port, java.lang.String path)
ScpLocation(java.lang.String username, java.lang.String host, java.lang.String path)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ScpLocation
clone()
boolean
equals(java.lang.Object obj)
java.lang.String
getHost()
java.lang.String
getPath()
int
getPort()
java.lang.String
getUsername()
int
hashCode()
boolean
isLocal()
static ScpLocation
parse(java.lang.String locSpec)
Parses a local or remote SCP location in the format "user@host:path" or "scp://[user@]host[:port][/path]"int
resolvePort()
java.lang.String
resolveUsername()
Resolves the effective username to use for a remote location.void
setHost(java.lang.String host)
void
setPath(java.lang.String path)
void
setPort(int port)
void
setUsername(java.lang.String username)
java.lang.String
toString()
static <L extends ScpLocation>
Lupdate(java.lang.String spec, L location)
Parses a local or remote SCP location in the format "user@host:path" or "scp://[user@]host[:port][/path]"
-
-
-
Field Detail
-
SCHEME
public static final java.lang.String SCHEME
- See Also:
- Constant Field Values
-
HOST_PART_SEPARATOR
public static final char HOST_PART_SEPARATOR
- See Also:
- Constant Field Values
-
USERNAME_PART_SEPARATOR
public static final char USERNAME_PART_SEPARATOR
- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
host
private java.lang.String host
-
username
private java.lang.String username
-
path
private java.lang.String path
-
port
private int port
-
-
Constructor Detail
-
ScpLocation
public ScpLocation()
-
ScpLocation
public ScpLocation(java.lang.String locSpec)
- Parameters:
locSpec
- The location specification - ignored ifnull
/empty- Throws:
java.lang.IllegalArgumentException
- if invalid specification- See Also:
update(String, ScpLocation)
-
ScpLocation
public ScpLocation(java.lang.String username, java.lang.String host, java.lang.String path)
-
ScpLocation
public ScpLocation(java.lang.String username, java.lang.String host, int port, java.lang.String path)
-
-
Method Detail
-
getHost
public java.lang.String getHost()
-
setHost
public void setHost(java.lang.String host)
-
isLocal
public boolean isLocal()
-
getPort
public int getPort()
-
setPort
public void setPort(int port)
-
resolvePort
public int resolvePort()
-
getUsername
public java.lang.String getUsername()
- Specified by:
getUsername
in interfaceUsernameHolder
- Returns:
- The attached username - may be
null
/empty if holder not yet initialized
-
setUsername
public void setUsername(java.lang.String username)
- Specified by:
setUsername
in interfaceMutableUserHolder
-
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
clone
public ScpLocation clone()
- Overrides:
clone
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
parse
public static ScpLocation parse(java.lang.String locSpec)
Parses a local or remote SCP location in the format "user@host:path" or "scp://[user@]host[:port][/path]"- Parameters:
locSpec
- The location specification - ignored ifnull
/empty- Returns:
- The
ScpLocation
ornull
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 spec, L location)
Parses a local or remote SCP location in the format "user@host:path" or "scp://[user@]host[:port][/path]"- Type Parameters:
L
- Type ofScpLocation
being updated- Parameters:
spec
- The location specification - ignored ifnull
/emptylocation
- TheScpLocation
to update - nevernull
- Returns:
- The updated location (unless no specification)
- Throws:
java.lang.IllegalArgumentException
- if invalid specification
-
-