public final class SftpHelper extends Object
Modifier and Type | Field and Description |
---|---|
static Map<Integer,String> |
DEFAULT_SUBSTATUS_MESSAGE |
Modifier and Type | Method and Description |
---|---|
static int |
attributesToPermissions(boolean isReg,
boolean isDir,
boolean isLnk,
Collection<PosixFilePermission> perms)
Converts a file / folder's attributes into a mask
|
static AclEntry |
buildAclEntry(int aclType,
int aclFlag,
int aclMask,
String aclWho) |
static AclEntryType |
decodeAclEntryType(int aclType) |
static Set<AclEntryFlag> |
decodeAclFlags(int aclFlag) |
static Set<AclEntryPermission> |
decodeAclMask(int aclMask) |
static List<AclEntry> |
decodeACLs(Buffer buffer,
int version) |
static int |
encodeAclEntryType(AclEntryType type)
Returns the equivalent SFTP value for the ACL type
|
static long |
encodeAclFlags(Collection<AclEntryFlag> flags) |
static long |
encodeAclMask(Collection<AclEntryPermission> mask) |
static <B extends Buffer> |
encodeACLs(B buffer,
int version,
Collection<AclEntry> acl) |
static int |
fileTypeToPermission(int type)
Converts a file type into a POSIX permission mask value
|
static boolean |
getBool(Boolean bool) |
static Boolean |
getEndOfFileIndicatorValue(Buffer buffer,
int version)
Retrieves the end-of-file indicator for
SSH_FXP_DATA responses, provided the version is at least 6, and
the buffer has enough available data |
static Boolean |
getEndOfListIndicatorValue(Buffer buffer,
int version)
Retrieves the end-of-list indicator for
SSH_FXP_NAME responses, provided the version is at least 6, and
the buffer has enough available data |
static String |
getLongName(String shortName,
Map<String,?> attributes)
Creates an "ls -l" compatible long name string
|
static Boolean |
indicateEndOfNamesList(Buffer buffer,
int version,
PropertyResolver resolver)
Appends the end-of-list=
TRUE indicator for SSH_FXP_NAME responses, provided the version is at
least 6 and the feature is enabled |
static Boolean |
indicateEndOfNamesList(Buffer buffer,
int version,
PropertyResolver resolver,
boolean indicatorValue)
Appends the end-of-list indicator for
SSH_FXP_NAME responses, provided the version is at least 6, the
feature is enabled and the indicator value is not null |
static Set<PosixFilePermission> |
permissionsToAttributes(int perms)
Translates a mask of permissions into its enumeration values equivalents
|
static int |
permissionsToFileType(int perms)
Converts a POSIX permissions mask to a file type value
|
static List<AclEntry> |
readACLs(Buffer buffer,
int version) |
static NavigableMap<String,Object> |
readAttrs(Buffer buffer,
int version) |
static NavigableMap<String,byte[]> |
readExtensions(Buffer buffer) |
static FileTime |
readTime(Buffer buffer,
int version,
int flags)
Decodes a
FileTime value from a buffer |
static String |
resolveStatusMessage(int subStatus) |
static int |
resolveSubstatus(Throwable t)
Returns the most adequate sub-status for the provided exception
|
static NavigableMap<String,byte[]> |
toBinaryExtensions(Map<String,String> extensions) |
static NavigableMap<String,String> |
toStringExtensions(Map<String,?> extensions) |
static <B extends Buffer> |
writeAclEntry(B buffer,
AclEntry acl) |
static <B extends Buffer> |
writeACLs(B buffer,
int version,
Collection<AclEntry> acl) |
static <B extends Buffer> |
writeAttributes(B buffer,
SftpClient.Attributes attributes,
int sftpVersion) |
static <B extends Buffer> |
writeAttrs(B buffer,
int version,
Map<String,?> attributes)
Writes a file / folder's attributes to a buffer
|
static <B extends Buffer> |
writeAttrsV3(B buffer,
int version,
Map<String,?> attributes)
Writes the retrieved file / directory attributes in V3 format
|
static <B extends Buffer> |
writeAttrsV4(B buffer,
int version,
Map<String,?> attributes)
Writes the retrieved file / directory attributes in V4+ format
|
static <B extends Buffer> |
writeExtensions(B buffer,
Map<?,?> extensions) |
static <B extends Buffer> |
writeTime(B buffer,
int version,
int flags,
FileTime time)
Encodes a
FileTime value into a buffer |
public static Boolean getEndOfFileIndicatorValue(Buffer buffer, int version)
SSH_FXP_DATA
responses, provided the version is at least 6, and
the buffer has enough available databuffer
- The Buffer
to retrieve the data fromversion
- The SFTP version being usednull
if none retrievedpublic static Boolean getEndOfListIndicatorValue(Buffer buffer, int version)
SSH_FXP_NAME
responses, provided the version is at least 6, and
the buffer has enough available databuffer
- The Buffer
to retrieve the data fromversion
- The SFTP version being usednull
if none retrievedindicateEndOfNamesList(Buffer, int, PropertyResolver, boolean)
public static Boolean indicateEndOfNamesList(Buffer buffer, int version, PropertyResolver resolver)
TRUE
indicator for SSH_FXP_NAME
responses, provided the version is at
least 6 and the feature is enabledbuffer
- The Buffer
to append the indicatorversion
- The SFTP version being usedresolver
- The PropertyResolver
to query whether to enable the featurenull
if none appendedindicateEndOfNamesList(Buffer, int, PropertyResolver, boolean)
public static Boolean indicateEndOfNamesList(Buffer buffer, int version, PropertyResolver resolver, boolean indicatorValue)
SSH_FXP_NAME
responses, provided the version is at least 6, the
feature is enabled and the indicator value is not null
buffer
- The Buffer
to append the indicatorversion
- The SFTP version being usedresolver
- The PropertyResolver
to query whether to enable the featureindicatorValue
- The indicator value - null
means don't append the indicatornull
if none appendedSftpModuleProperties.APPEND_END_OF_LIST_INDICATOR
public static <B extends Buffer> B writeAttrs(B buffer, int version, Map<String,?> attributes)
B
- Type of Buffer
being updatedbuffer
- The target buffer instanceversion
- The output encoding versionattributes
- The Map
of attributeswriteAttrsV3(Buffer, int, Map)
,
writeAttrsV4(Buffer, int, Map)
public static <B extends Buffer> B writeAttrsV3(B buffer, int version, Map<String,?> attributes)
B
- Type of Buffer
being updatedbuffer
- The target buffer instanceversion
- The actual version - must be SftpConstants.SFTP_V3
attributes
- The Map
of attributespublic static <B extends Buffer> B writeAttrsV4(B buffer, int version, Map<String,?> attributes)
B
- Type of Buffer
being updatedbuffer
- The target buffer instanceversion
- The actual version - must be at least SftpConstants.SFTP_V4
attributes
- The Map
of attributespublic static <B extends Buffer> B writeAttributes(B buffer, SftpClient.Attributes attributes, int sftpVersion)
public static boolean getBool(Boolean bool)
bool
- The Boolean
valuetrue
it the argument is non-null
and its Boolean.booleanValue()
is
true
public static int attributesToPermissions(boolean isReg, boolean isDir, boolean isLnk, Collection<PosixFilePermission> perms)
isReg
- true
if this is a normal fileisDir
- true
if this is a directoryisLnk
- true
if this is a symbolic linkperms
- The file / folder's access PosixFilePermission
spublic static int permissionsToFileType(int perms)
perms
- The POSIX permissions maskSSH_FILEXFER_TYPE_xxx
valuespublic static int fileTypeToPermission(int type)
type
- File type - see SSH_FILEXFER_TYPE_xxx
valuespublic static Set<PosixFilePermission> permissionsToAttributes(int perms)
perms
- The permissions maskSet
of the equivalent PosixFilePermission
spublic static int resolveSubstatus(Throwable t)
t
- The thrown Throwable
public static String resolveStatusMessage(int subStatus)
public static NavigableMap<String,Object> readAttrs(Buffer buffer, int version)
public static NavigableMap<String,byte[]> readExtensions(Buffer buffer)
public static NavigableMap<String,String> toStringExtensions(Map<String,?> extensions)
public static NavigableMap<String,byte[]> toBinaryExtensions(Map<String,String> extensions)
public static AclEntry buildAclEntry(int aclType, int aclFlag, int aclMask, String aclWho)
public static AclEntryType decodeAclEntryType(int aclType)
aclType
- The ACE4_ACCESS_xxx_ACE_TYPE
valueAclEntryType
or null
if unknown valuepublic static Set<AclEntryFlag> decodeAclFlags(int aclFlag)
public static Set<AclEntryPermission> decodeAclMask(int aclMask)
public static <B extends Buffer> B writeACLs(B buffer, int version, Collection<AclEntry> acl)
public static <B extends Buffer> B encodeACLs(B buffer, int version, Collection<AclEntry> acl)
public static int encodeAclEntryType(AclEntryType type)
type
- The AclEntryType
ACE_SYSTEM_xxx_TYPE
or negative if null
or unknown typepublic static long encodeAclFlags(Collection<AclEntryFlag> flags)
public static long encodeAclMask(Collection<AclEntryPermission> mask)
public static <B extends Buffer> B writeTime(B buffer, int version, int flags, FileTime time)
FileTime
value into a bufferB
- Type of Buffer
being updatedbuffer
- The target buffer instanceversion
- The encoding versionflags
- The encoding flagstime
- The value to encodepublic static FileTime readTime(Buffer buffer, int version, int flags)
FileTime
value from a bufferbuffer
- The source Buffer
version
- The encoding versionflags
- The encoding flagspublic static String getLongName(String shortName, Map<String,?> attributes)
shortName
- The short file name - can also be "." or ".."attributes
- The file's attributes - e.g., size, owner, permissions, etc.String
representing the "long" file name as per
SFTP version 3 - section
7Copyright © 2008–2024 The Apache Software Foundation. All rights reserved.