public class FileUtilLimitedImpl extends AbstractLoggableComponent implements FileUtilLimited
File
handling and manipulation.getInstance()
Modifier and Type | Field and Description |
---|---|
protected static String |
HOME_ROOT
The typical home directory of the user "root" under Unix/Linux.
|
private static FileUtilLimited |
instance |
protected static String |
UNC_PATH_PREFIX
The prefix of an UNC (Uniform Naming Convention) path (e.g.
|
protected static Pattern |
URL_SCHEMA_PATTERN
|
NO_FILES, PATH_SEGMENT_CURRENT, PATH_SEGMENT_PARENT, PROPERTY_TMP_DIR, PROPERTY_USER_HOME
Constructor and Description |
---|
FileUtilLimitedImpl()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
String |
getBasename(String filename)
This method gets the basename of the given
filename (path). |
String |
getDirname(String filename)
This method gets the directory-name of the given
filename (path). |
String |
getExtension(String filename)
This method extracts the extension from the given
filename . |
static FileUtilLimited |
getInstance()
This method gets the singleton instance of this
FileUtilLimitedImpl . |
protected String |
getUserHomeDirectoryPath() |
protected String |
getUserLogin() |
String |
normalizePath(String path)
This method is a shortcut for
. |
String |
normalizePath(String path,
char separator)
This method normalizes a given
path . |
private String |
normalizePathInternal(String path,
char slash)
This method handles
normalizePath(String) internally. |
createLogger, doInitialize, getLogger
doInitialized, getInitializationState, initialize
protected static final String HOME_ROOT
protected static final String UNC_PATH_PREFIX
\\10.0.0.1\share
).protected static final Pattern URL_SCHEMA_PATTERN
private static FileUtilLimited instance
getInstance()
public static FileUtilLimited getInstance()
FileUtilLimitedImpl
. Cdi.GET_INSTANCE
before using.public String normalizePath(String path)
normalizePath
(path,
File.separatorChar
)
.normalizePath
in interface FileUtilLimited
path
- is the path to resolve.FileUtilLimited.normalizePath(String, char)
public String normalizePath(String path, char separator)
path
. It will resolve ".." and "." segments, normalize
backslashes and remove duplicated slashes. Further it can resolve "~" at the beginning of the path (like
in bash-scripts, etc.). Therefore this method resolves the path in such situations (e.g. to
"/home/login/foo") and returns a physical path. separator
is '/' (backslashes are NOT escaped):
path |
normalizePath(path) |
---|---|
"folder/subfolder//../.\some.file" |
"folder/some.file" |
"../.\some.file" |
"../some.file" |
"http://www.host.com/foo/bar/./test/.././.." |
"http://www.host.com/foo" |
"\\unc.host\printers\pr3761" |
"\\unc.host\printers\pr3761" |
"~/documents/index.html" |
|
"~root/subfolder/../folder/.//index.html" |
"/root/folder/index.html" |
normalizePath
in interface FileUtilLimited
path
- is the path to resolve.separator
- is the character to use as file separator
.protected String getUserHomeDirectoryPath()
protected String getUserLogin()
private String normalizePathInternal(String path, char slash)
normalizePath(String)
internally.path
- is the path.slash
- is the character used to to separate folders.public String getExtension(String filename)
filename
. getExtension
("test.java")
would return
"java"
. filename
is just a dot followed by the extension (e.g. ".java"
), the
empty string is returned.getExtension
in interface FileUtilLimited
filename
- is the filename and may include an absolute or relative path.filename
excluding the dot in
lowercase
or the empty string if NOT present.public String getBasename(String filename)
filename
(path). The basename is the raw
name of the file without the path
. filename |
|
---|---|
/ | / |
\/\ | \ |
/. | . |
/foo.bar | foo.bar |
/foo/bar/ | bar |
c:\\ | |
c:\\foo | foo |
http://foo.org/bar | bar |
getBasename
in interface FileUtilLimited
filename
- is the path to a file or directory.filename
.public String getDirname(String filename)
filename
(path). filename | FileUtilLimited.getDirname(String) |
---|---|
foo | . |
/foo | / |
/foo/bar | /foo |
/foo/bar/ | /foo |
./foo/bar/ | ./foo |
./foo/bar/../ | ./foo/bar |
getDirname
in interface FileUtilLimited
filename
- is the path to a file or directory.filename
.FileUtilLimited.normalizePath(String)
Copyright © 2001–2014 mmm-Team. All rights reserved.