Package org.apache.commons.vfs2.provider
Class HostFileNameParser
java.lang.Object
org.apache.commons.vfs2.provider.AbstractFileNameParser
org.apache.commons.vfs2.provider.HostFileNameParser
- All Implemented Interfaces:
FileNameParser
- Direct Known Subclasses:
FtpFileNameParser
,GenericURLFileNameParser
,URLFileNameParser
Implementation for any URL based file system.
Parses the URL into user/password/host/port/path. Does not handle a query string (after ?).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Parsed authority info (scheme, hostname, username/password, port). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
extractHostName
(StringBuilder name) Extracts the hostname from a URI.protected int
extractPort
(StringBuilder name, String uri) Extracts the port from a URI.protected HostFileNameParser.Authority
extractToPath
(String uri, StringBuilder name) Deprecated.protected HostFileNameParser.Authority
extractToPath
(VfsComponentContext context, String uri, StringBuilder name) Extracts the scheme, userinfo, hostname and port components of a generic URI.protected String
extractUserInfo
(StringBuilder name) Extracts the user info from a URI.int
Gets the default port.parseUri
(VfsComponentContext context, FileName base, String fileName) Parses a String into a file name.Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileNameParser
encodeCharacter
-
Constructor Details
-
HostFileNameParser
Constructs a new instance.- Parameters:
defaultPort
- The default port.
-
-
Method Details
-
extractHostName
Extracts the hostname from a URI.- Parameters:
name
- string buffer with the "scheme://[userinfo@]" part has been removed already. Will be modified.- Returns:
- the host name or null.
-
extractPort
Extracts the port from a URI.- Parameters:
name
- string buffer with the "scheme://[userinfo@]hostname" part has been removed already. Will be modified.uri
- full URI for error reporting.- Returns:
- The port, or -1 if the URI does not contain a port.
- Throws:
FileSystemException
- if URI is malformed.NumberFormatException
- if port number cannot be parsed.
-
extractToPath
@Deprecated protected HostFileNameParser.Authority extractToPath(String uri, StringBuilder name) throws FileSystemException Deprecated.Extracts the scheme, userinfo, hostname and port components of a generic URI.- Parameters:
uri
- The absolute URI to parse.name
- Used to return the remainder of the URI.- Returns:
- Authority extracted host authority, never null.
- Throws:
FileSystemException
- if authority cannot be extracted.
-
extractToPath
protected HostFileNameParser.Authority extractToPath(VfsComponentContext context, String uri, StringBuilder name) throws FileSystemException Extracts the scheme, userinfo, hostname and port components of a generic URI.- Parameters:
context
- component context.uri
- The absolute URI to parse.name
- Used to return the remainder of the URI.- Returns:
- Authority extracted host authority, never null.
- Throws:
FileSystemException
- if authority cannot be extracted.
-
extractUserInfo
Extracts the user info from a URI.- Parameters:
name
- string buffer with the "scheme://" part has been removed already. Will be modified.- Returns:
- the user information up to the '@' or null.
-
getDefaultPort
Gets the default port.- Returns:
- the default port.
-
parseUri
public FileName parseUri(VfsComponentContext context, FileName base, String fileName) throws FileSystemException Description copied from interface:FileNameParser
Parses a String into a file name.- Parameters:
context
- The component context.base
- The base FileName.fileName
- The target file name.- Returns:
- A FileName that represents the taret file.
- Throws:
FileSystemException
- if an error occurs parsing the URI.
-
extractToPath(VfsComponentContext, String, StringBuilder)
.