Top Description Fields Constructors Methods
org.apache.sshd.common.util

public final Class SelectorUtils

extends Object
Class Inheritance
Imports
java.io.File, java.nio.file.FileSystem, java.util.ArrayList, .List, .Objects, .StringTokenizer

This is a utility class used by selectors and DirectoryScanner. The functionality more properly belongs just to selectors, but unfortunately DirectoryScanner exposed these as protected methods. Thus we have to support any subclasses of DirectoryScanner that may access these methods.

This is a Singleton.

Authors
Arnout J. Kuiper [email protected], Magesh Umasankar, Bruce Atherton
Since
1.5
Version
$Id$

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String

Constructor Summary

AccessConstructor and Description
private
SelectorUtils()

Private Constructor

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

The effective path - may be same as input if no changes required
applySlashifyRules
(String
The original path - ignored if null/empty or does not contain any slashes
path
,
char
The "slash" character
sepChar
)

Applies the "slashification" rules as specified in Single Unix Specification version 3, section 3.266 and section 4.11 - Pathname resolution

public static String

Returns:

Concatenation result
concatPaths
(String
prefix part - ignored if null/empty
p1
,
String
suffix part - ignored if null/empty
p2
,
char
The expected file-system separator
fsSeparator
)

Creates a single path by concatenating 2 parts and taking care not to create FS separator duplication in the process

public static boolean

Returns:

true if equal characters
equals
(char
1st character
c1
,
char
2nd character
c2
,
boolean
Whether to compare case sensitive
isCaseSensitive
)

Tests whether two characters are equal.

public static boolean
public static boolean
isWindowsDriveSpecified(CharSequence cs, int offset, int len)

public static boolean

Returns:

true if the string matches against the pattern, or false otherwise.
match
(String
The pattern to match against. Must not be null.
pattern
,
String
The string which must be matched against the pattern. Must not be null.
str
)

Tests whether or not a string matches against a pattern.

public static boolean

Returns:

true if the string matches against the pattern, or false otherwise.
match
(String
The pattern to match against. Must not be null.
pattern
,
String
The string which must be matched against the pattern. Must not be null.
str
,
boolean
Whether or not matching should be performed case sensitively.
isCaseSensitive
)

Tests whether or not a string matches against a pattern.

public static boolean
matchAntPathPattern(String pattern, String str, boolean isCaseSensitive)

public static boolean
matchAntPathPattern(String pattern, String str, String separator, boolean isCaseSensitive)

public static boolean
matchAntPathPatternStart(String pattern, String str, String separator, boolean isCaseSensitive)

public static boolean

Returns:

true if the pattern matches against the string, or false otherwise.
matchPath
(String
The pattern to match against. Must not be null.
pattern
,
String
The path to match, as a String. Must not be null.
str
)

Tests whether or not a given path matches a given pattern.

public static boolean

Returns:

true if the pattern matches against the string, or false otherwise.
matchPath
(String
The pattern to match against. Must not be null.
pattern
,
String
The path to match, as a String. Must not be null.
str
,
boolean
Whether or not matching should be performed case sensitively.
isCaseSensitive
)

Tests whether or not a given path matches a given pattern.

public static boolean
matchPath(String pattern, String str, String separator, boolean isCaseSensitive)

public static boolean

Returns:

whether or not a given path matches the start of a given pattern up to the first "**".
matchPatternStart
(String
The pattern to match against. Must not be null.
pattern
,
String
The path to match, as a String. Must not be null.
str
)

Tests whether or not a given path matches the start of a given pattern up to the first "**".

public static boolean

Returns:

whether or not a given path matches the start of a given pattern up to the first "**".
matchPatternStart
(String
The pattern to match against. Must not be null.
pattern
,
String
The path to match, as a String. Must not be null.
str
,
boolean
Whether or not matching should be performed case sensitively.
isCaseSensitive
)

Tests whether or not a given path matches the start of a given pattern up to the first "**".

public static boolean
matchPatternStart(String pattern, String str, String separator, boolean isCaseSensitive)

public static String

Returns:

a String that has had all whitespace removed.
removeWhitespace
(String
a String to remove all whitespace.
input
)

"Flattens" a string by removing all whitespace (space, tab, line-feed, carriage return, and form-feed).

public static List<String>

Returns:

a List of path elements from the tokenized path
tokenizePath
(String
Path to tokenize. Must not be null.
path
)

Breaks a path up into a Vector of path elements, tokenizing on File.separator.

public static List<String>
tokenizePath(String path, String separator)

public static String

Returns:

The path where the separator used to build it is replaced by the file-system one (if different)
translateToFileSystemPath
(String
The input path - ignored if null/empty
path
,
String
The separator used to build the input path - may not be null/empty
pathSeparator
,
FileSystem
The target FileSystem - may not be null
fs
)

Converts a path containing a specific separator to one using the specified file-system one

public static String

Returns:

The path where the separator used to build it is replaced by the file-system one (if different)
translateToFileSystemPath
(String
The input path - ignored if null/empty
path
,
String
The separator used to build the input path - may not be null/empty
pathSeparator
,
String
The target file system separator - may not be null/empty
fsSeparator
)

Converts a path containing a specific separator to one using the specified file-system one

public static String

Returns:

The transformed path
translateToLocalFileSystemPath
(String
The input path
path
,
char
The separator used to build the input path
pathSeparator
,
FileSystem
The target FileSystem - may not be null
fs
)

/** Converts a path to one matching the target file system by applying the "slashification" rules, converting it to a local path and then translating its separator to the target file system one (if different than local one)

public static String

Returns:

The transformed path
translateToLocalFileSystemPath
(String
The input path
path
,
char
The separator used to build the input path
pathSeparator
,
String
The target file system separator
fsSeparator
)

Converts a path to one matching the target file system by applying the "slashification" rules, converting it to a local path and then translating its separator to the target file system one (if different than local one)

public static String

Returns:

The local path
translateToLocalPath
(String
The original path - ignored if null/empty
path
)

Converts a possibly '/' separated path to a local path

Note

takes special care of Windows drive paths - e.g., C: by converting them to "C:\"

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANT_HANDLER_PREFIXback to summary
public static final String ANT_HANDLER_PREFIX
PATTERN_HANDLER_PREFIXback to summary
public static final String PATTERN_HANDLER_PREFIX
PATTERN_HANDLER_SUFFIXback to summary
public static final String PATTERN_HANDLER_SUFFIX
REGEX_HANDLER_PREFIXback to summary
public static final String REGEX_HANDLER_PREFIX

Constructor Detail

SelectorUtilsback to summary
private SelectorUtils()

Private Constructor

Method Detail

applySlashifyRulesback to summary
public static String applySlashifyRules(String path, char sepChar)

Applies the "slashification" rules as specified in Single Unix Specification version 3, section 3.266 and section 4.11 - Pathname resolution

Parameters
path:String

The original path - ignored if null/empty or does not contain any slashes

sepChar:char

The "slash" character

Returns:String

The effective path - may be same as input if no changes required

concatPathsback to summary
public static String concatPaths(String p1, String p2, char fsSeparator)

Creates a single path by concatenating 2 parts and taking care not to create FS separator duplication in the process

Parameters
p1:String

prefix part - ignored if null/empty

p2:String

suffix part - ignored if null/empty

fsSeparator:char

The expected file-system separator

Returns:String

Concatenation result

equalsback to summary
public static boolean equals(char c1, char c2, boolean isCaseSensitive)

Tests whether two characters are equal.

Parameters
c1:char

1st character

c2:char

2nd character

isCaseSensitive:boolean

Whether to compare case sensitive

Returns:boolean

true if equal characters

isWindowsDriveSpecifiedback to summary
public static boolean isWindowsDriveSpecified(CharSequence cs)
isWindowsDriveSpecifiedback to summary
public static boolean isWindowsDriveSpecified(CharSequence cs, int offset, int len)
matchback to summary
public static boolean match(String pattern, String str)

Tests whether or not a string matches against a pattern. The pattern may contain two special characters:
'*' means zero or more characters
'?' means one and only one character

Parameters
pattern:String

The pattern to match against. Must not be null.

str:String

The string which must be matched against the pattern. Must not be null.

Returns:boolean

true if the string matches against the pattern, or false otherwise.

matchback to summary
public static boolean match(String pattern, String str, boolean isCaseSensitive)

Tests whether or not a string matches against a pattern. The pattern may contain two special characters:
'*' means zero or more characters
'?' means one and only one character

Parameters
pattern:String

The pattern to match against. Must not be null.

str:String

The string which must be matched against the pattern. Must not be null.

isCaseSensitive:boolean

Whether or not matching should be performed case sensitively.

Returns:boolean

true if the string matches against the pattern, or false otherwise.

Annotations
@SuppressWarnings:PMD.AssignmentInOperand
matchAntPathPatternback to summary
public static boolean matchAntPathPattern(String pattern, String str, boolean isCaseSensitive)
matchAntPathPatternback to summary
public static boolean matchAntPathPattern(String pattern, String str, String separator, boolean isCaseSensitive)
matchAntPathPatternStartback to summary
public static boolean matchAntPathPatternStart(String pattern, String str, String separator, boolean isCaseSensitive)
matchPathback to summary
public static boolean matchPath(String pattern, String str)

Tests whether or not a given path matches a given pattern.

Parameters
pattern:String

The pattern to match against. Must not be null.

str:String

The path to match, as a String. Must not be null.

Returns:boolean

true if the pattern matches against the string, or false otherwise.

matchPathback to summary
public static boolean matchPath(String pattern, String str, boolean isCaseSensitive)

Tests whether or not a given path matches a given pattern.

Parameters
pattern:String

The pattern to match against. Must not be null.

str:String

The path to match, as a String. Must not be null.

isCaseSensitive:boolean

Whether or not matching should be performed case sensitively.

Returns:boolean

true if the pattern matches against the string, or false otherwise.

matchPathback to summary
public static boolean matchPath(String pattern, String str, String separator, boolean isCaseSensitive)
matchPatternStartback to summary
public static boolean matchPatternStart(String pattern, String str)

Tests whether or not a given path matches the start of a given pattern up to the first "**".

This is not a general purpose test and should only be used if you can live with false positives. For example, pattern=**\a and str=b will yield true.

Parameters
pattern:String

The pattern to match against. Must not be null.

str:String

The path to match, as a String. Must not be null.

Returns:boolean

whether or not a given path matches the start of a given pattern up to the first "**".

matchPatternStartback to summary
public static boolean matchPatternStart(String pattern, String str, boolean isCaseSensitive)

Tests whether or not a given path matches the start of a given pattern up to the first "**".

This is not a general purpose test and should only be used if you can live with false positives. For example, pattern=**\a and str=b will yield true.

Parameters
pattern:String

The pattern to match against. Must not be null.

str:String

The path to match, as a String. Must not be null.

isCaseSensitive:boolean

Whether or not matching should be performed case sensitively.

Returns:boolean

whether or not a given path matches the start of a given pattern up to the first "**".

matchPatternStartback to summary
public static boolean matchPatternStart(String pattern, String str, String separator, boolean isCaseSensitive)
removeWhitespaceback to summary
public static String removeWhitespace(String input)

"Flattens" a string by removing all whitespace (space, tab, line-feed, carriage return, and form-feed). This uses StringTokenizer and the default set of tokens as documented in the single argument constructor.

Parameters
input:String

a String to remove all whitespace.

Returns:String

a String that has had all whitespace removed.

tokenizePathback to summary
public static List<String> tokenizePath(String path)

Breaks a path up into a Vector of path elements, tokenizing on File.separator.

Parameters
path:String

Path to tokenize. Must not be null.

Returns:List<String>

a List of path elements from the tokenized path

tokenizePathback to summary
public static List<String> tokenizePath(String path, String separator)
translateToFileSystemPathback to summary
public static String translateToFileSystemPath(String path, String pathSeparator, FileSystem fs)

Converts a path containing a specific separator to one using the specified file-system one

Parameters
path:String

The input path - ignored if null/empty

pathSeparator:String

The separator used to build the input path - may not be null/empty

fs:FileSystem

The target FileSystem - may not be null

Returns:String

The path where the separator used to build it is replaced by the file-system one (if different)

See Also
FileSystem#getSeparator(), translateToFileSystemPath(String, String, String)
translateToFileSystemPathback to summary
public static String translateToFileSystemPath(String path, String pathSeparator, String fsSeparator)

Converts a path containing a specific separator to one using the specified file-system one

Parameters
path:String

The input path - ignored if null/empty

pathSeparator:String

The separator used to build the input path - may not be null/empty

fsSeparator:String

The target file system separator - may not be null/empty

Returns:String

The path where the separator used to build it is replaced by the file-system one (if different)

Exceptions
IllegalArgumentException:
if path or file-system separator are null/empty or if the separators are different and the path contains the target file-system separator as it would create an ambiguity
translateToLocalFileSystemPathback to summary
public static String translateToLocalFileSystemPath(String path, char pathSeparator, FileSystem fs)

/** Converts a path to one matching the target file system by applying the "slashification" rules, converting it to a local path and then translating its separator to the target file system one (if different than local one)

Parameters
path:String

The input path

pathSeparator:char

The separator used to build the input path

fs:FileSystem

The target FileSystem - may not be null

Returns:String

The transformed path

See Also
translateToLocalFileSystemPath(String, char, String)
translateToLocalFileSystemPathback to summary
public static String translateToLocalFileSystemPath(String path, char pathSeparator, String fsSeparator)

Converts a path to one matching the target file system by applying the "slashification" rules, converting it to a local path and then translating its separator to the target file system one (if different than local one)

Parameters
path:String

The input path

pathSeparator:char

The separator used to build the input path

fsSeparator:String

The target file system separator

Returns:String

The transformed path

See Also
applySlashifyRules(String, char), translateToLocalPath(String), translateToFileSystemPath(String, String, String)
translateToLocalPathback to summary
public static String translateToLocalPath(String path)

Converts a possibly '/' separated path to a local path

Note

takes special care of Windows drive paths - e.g., C: by converting them to "C:\"

Parameters
path:String

The original path - ignored if null/empty

Returns:String

The local path