Package javax.mail
Class URLName
- java.lang.Object
-
- javax.mail.URLName
-
public class URLName extends java.lang.ObjectThe name of a URL. This class represents a URL name and also provides the basic parsing functionality to parse most internet standard URL schemes.Note that this class differs from
java.net.URLin that this class just represents the name of a URL, it does not model the connection to a URL.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intcaseDiffprivate static booleandoEncodeA way to turn off encoding, just in case...(package private) static java.util.BitSetdontNeedEncodingThe class contains a utility method for converting aStringinto a MIME format called "x-www-form-urlencoded" format.private java.lang.StringfileThe specified file name on that host.protected java.lang.StringfullURLThe full version of the URLprivate inthashCodeOur hash code.private java.lang.StringhostThe host name to which to connect.private java.net.InetAddresshostAddressThe host's IP address, used in equals and hashCode.private booleanhostAddressKnownprivate java.lang.StringpasswordThe password to use when connecting.private intportThe protocol port to connect to.private java.lang.StringprotocolThe protocol to use (ftp, http, nntp, imap, pop3 ...private java.lang.Stringref# reference.private java.lang.StringusernameThe username to use when connecting
-
Constructor Summary
Constructors Constructor Description URLName(java.lang.String url)Construct a URLName from the string.URLName(java.lang.String protocol, java.lang.String host, int port, java.lang.String file, java.lang.String username, java.lang.String password)Creates a URLName object from the specified protocol, host, port number, file, username, and password.URLName(java.net.URL url)Construct a URLName from a java.net.URL object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String_encode(java.lang.String s)(package private) static java.lang.Stringdecode(java.lang.String s)Decodes a "x-www-form-urlencoded" to a String.(package private) static java.lang.Stringencode(java.lang.String s)Translates a string intox-www-form-urlencodedformat.booleanequals(java.lang.Object obj)Compares two URLNames.java.lang.StringgetFile()Returns the file name of this URLName.java.lang.StringgetHost()Returns the host of this URLName.private java.net.InetAddressgetHostAddress()Get the IP address of our host.java.lang.StringgetPassword()Returns the password of this URLName.intgetPort()Returns the port number of this URLName.java.lang.StringgetProtocol()Returns the protocol of this URLName.java.lang.StringgetRef()Returns the reference of this URLName.java.net.URLgetURL()Constructs a URL from the URLName.java.lang.StringgetUsername()Returns the user name of this URLName.inthashCode()Compute the hash code for this URLName.private static intindexOfAny(java.lang.String s, java.lang.String any)Return the first index of any of the characters in "any" in "s", or -1 if none are found.private static intindexOfAny(java.lang.String s, java.lang.String any, int start)protected voidparseString(java.lang.String url)Method which does all of the work of parsing the string.java.lang.StringtoString()Constructs a string representation of this URLName.
-
-
-
Field Detail
-
fullURL
protected java.lang.String fullURL
The full version of the URL
-
protocol
private java.lang.String protocol
The protocol to use (ftp, http, nntp, imap, pop3 ... etc.) .
-
username
private java.lang.String username
The username to use when connecting
-
password
private java.lang.String password
The password to use when connecting.
-
host
private java.lang.String host
The host name to which to connect.
-
hostAddress
private java.net.InetAddress hostAddress
The host's IP address, used in equals and hashCode. Computed on demand.
-
hostAddressKnown
private boolean hostAddressKnown
-
port
private int port
The protocol port to connect to.
-
file
private java.lang.String file
The specified file name on that host.
-
ref
private java.lang.String ref
# reference.
-
hashCode
private int hashCode
Our hash code.
-
doEncode
private static boolean doEncode
A way to turn off encoding, just in case...
-
dontNeedEncoding
static java.util.BitSet dontNeedEncoding
The class contains a utility method for converting aStringinto a MIME format called "x-www-form-urlencoded" format.To convert a
String, each character is examined in turn:- The ASCII characters '
a' through 'z', 'A' through 'Z', '0' through '9', and ".", "-", "*", "_" remain the same. - The space character '
' is converted into a plus sign '+'. - All other characters are converted into the 3-character string
"
%xy", where xy is the two-digit hexadecimal representation of the lower 8-bits of the character.
- Since:
- JDK1.0
- The ASCII characters '
-
caseDiff
static final int caseDiff
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
URLName
public URLName(java.lang.String protocol, java.lang.String host, int port, java.lang.String file, java.lang.String username, java.lang.String password)Creates a URLName object from the specified protocol, host, port number, file, username, and password. Specifying a port number of -1 indicates that the URL should use the default port for the protocol.- Parameters:
protocol- the protocolhost- the host nameport- the port numberfile- the fileusername- the user namepassword- the password
-
URLName
public URLName(java.net.URL url)
Construct a URLName from a java.net.URL object.- Parameters:
url- the URL
-
URLName
public URLName(java.lang.String url)
Construct a URLName from the string. Parses out all the possible information (protocol, host, port, file, username, password).- Parameters:
url- the URL string
-
-
Method Detail
-
toString
public java.lang.String toString()
Constructs a string representation of this URLName.- Overrides:
toStringin classjava.lang.Object
-
parseString
protected void parseString(java.lang.String url)
Method which does all of the work of parsing the string.- Parameters:
url- the URL string to parse
-
getPort
public int getPort()
Returns the port number of this URLName. Returns -1 if the port is not set.- Returns:
- the port number
-
getProtocol
public java.lang.String getProtocol()
Returns the protocol of this URLName. Returns null if this URLName has no protocol.- Returns:
- the protocol
-
getFile
public java.lang.String getFile()
Returns the file name of this URLName. Returns null if this URLName has no file name.- Returns:
- the file name of this URLName
-
getRef
public java.lang.String getRef()
Returns the reference of this URLName. Returns null if this URLName has no reference.- Returns:
- the reference part of the URLName
-
getHost
public java.lang.String getHost()
Returns the host of this URLName. Returns null if this URLName has no host.- Returns:
- the host name
-
getUsername
public java.lang.String getUsername()
Returns the user name of this URLName. Returns null if this URLName has no user name.- Returns:
- the user name
-
getPassword
public java.lang.String getPassword()
Returns the password of this URLName. Returns null if this URLName has no password.- Returns:
- the password
-
getURL
public java.net.URL getURL() throws java.net.MalformedURLExceptionConstructs a URL from the URLName.- Returns:
- the URL
- Throws:
java.net.MalformedURLException- if the URL is malformed
-
equals
public boolean equals(java.lang.Object obj)
Compares two URLNames. The result is true if and only if the argument is not null and is a URLName object that represents the same URLName as this object. Two URLName objects are equal if they have the same protocol and the same host, the same port number on the host, the same username, and the same file on the host. The fields (host, username, file) are also considered the same if they are both null.Hosts are considered equal if the names are equal (case independent) or if host name lookups for them both succeed and they both reference the same IP address.
Note that URLName has no knowledge of default port numbers for particular protocols, so "imap://host" and "imap://host:143" would not compare as equal.
Note also that the password field is not included in the comparison, nor is any reference field appended to the filename.
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Compute the hash code for this URLName.- Overrides:
hashCodein classjava.lang.Object
-
getHostAddress
private java.net.InetAddress getHostAddress()
Get the IP address of our host. Look up the name the first time and remember that we've done so, whether the lookup fails or not.
-
encode
static java.lang.String encode(java.lang.String s)
Translates a string intox-www-form-urlencodedformat.- Parameters:
s-Stringto be translated.- Returns:
- the translated
String.
-
_encode
private static java.lang.String _encode(java.lang.String s)
-
decode
static java.lang.String decode(java.lang.String s)
Decodes a "x-www-form-urlencoded" to a String.- Parameters:
s- theStringto decode- Returns:
- the newly decoded
String
-
indexOfAny
private static int indexOfAny(java.lang.String s, java.lang.String any)Return the first index of any of the characters in "any" in "s", or -1 if none are found. This should be a method on String.
-
indexOfAny
private static int indexOfAny(java.lang.String s, java.lang.String any, int start)
-
-