public class URLName
extends java.lang.Object
Note that this class differs from java.net.URL
in that this class just represents the name of a URL, it does
not model the connection to a URL.
Modifier and Type | Field and Description |
---|---|
(package private) static int |
caseDiff |
private static boolean |
doEncode
A way to turn off encoding, just in case...
|
(package private) static java.util.BitSet |
dontNeedEncoding
The class contains a utility method for converting a
String into a MIME format called
"x-www-form-urlencoded " format. |
private java.lang.String |
file
The specified file name on that host.
|
protected java.lang.String |
fullURL
The full version of the URL
|
private int |
hashCode
Our hash code.
|
private java.lang.String |
host
The host name to which to connect.
|
private java.net.InetAddress |
hostAddress
The host's IP address, used in equals and hashCode.
|
private boolean |
hostAddressKnown |
private java.lang.String |
password
The password to use when connecting.
|
private int |
port
The protocol port to connect to.
|
private java.lang.String |
protocol
The protocol to use (ftp, http, nntp, imap, pop3 ...
|
private java.lang.String |
ref
# reference.
|
private java.lang.String |
username
The username to use when connecting
|
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
_encode(java.lang.String s) |
(package private) static java.lang.String |
decode(java.lang.String s)
Decodes a "x-www-form-urlencoded"
to a String.
|
(package private) static java.lang.String |
encode(java.lang.String s)
Translates a string into
x-www-form-urlencoded format. |
boolean |
equals(java.lang.Object obj)
Compares two URLNames.
|
java.lang.String |
getFile()
Returns the file name of this URLName.
|
java.lang.String |
getHost()
Returns the host of this URLName.
|
private java.net.InetAddress |
getHostAddress()
Get the IP address of our host.
|
java.lang.String |
getPassword()
Returns the password of this URLName.
|
int |
getPort()
Returns the port number of this URLName.
|
java.lang.String |
getProtocol()
Returns the protocol of this URLName.
|
java.lang.String |
getRef()
Returns the reference of this URLName.
|
java.net.URL |
getURL()
Constructs a URL from the URLName.
|
java.lang.String |
getUsername()
Returns the user name of this URLName.
|
int |
hashCode()
Compute the hash code for this URLName.
|
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.
|
private static int |
indexOfAny(java.lang.String s,
java.lang.String any,
int start) |
protected void |
parseString(java.lang.String url)
Method which does all of the work of parsing the string.
|
java.lang.String |
toString()
Constructs a string representation of this URLName.
|
protected java.lang.String fullURL
private java.lang.String protocol
private java.lang.String username
private java.lang.String password
private java.lang.String host
private java.net.InetAddress hostAddress
private boolean hostAddressKnown
private int port
private java.lang.String file
private java.lang.String ref
private int hashCode
private static boolean doEncode
static java.util.BitSet dontNeedEncoding
String
into a MIME format called
"x-www-form-urlencoded
" format.
To convert a String
, each character is examined in turn:
a
' through 'z
',
'A
' through 'Z
', '0
'
through '9
', and ".", "-",
"*", "_" remain the same.
' is converted into a
plus sign '+
'.
%xy
", where xy is the two-digit
hexadecimal representation of the lower 8-bits of the character.
static final int caseDiff
public URLName(java.lang.String protocol, java.lang.String host, int port, java.lang.String file, java.lang.String username, java.lang.String password)
protocol
- the protocolhost
- the host nameport
- the port numberfile
- the fileusername
- the user namepassword
- the passwordpublic URLName(java.net.URL url)
url
- the URLpublic URLName(java.lang.String url)
url
- the URL stringpublic java.lang.String toString()
toString
in class java.lang.Object
protected void parseString(java.lang.String url)
url
- the URL string to parsepublic int getPort()
public java.lang.String getProtocol()
public java.lang.String getFile()
public java.lang.String getRef()
public java.lang.String getHost()
public java.lang.String getUsername()
public java.lang.String getPassword()
public java.net.URL getURL() throws java.net.MalformedURLException
java.net.MalformedURLException
- if the URL is malformedpublic boolean equals(java.lang.Object obj)
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.
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
private java.net.InetAddress getHostAddress()
static java.lang.String encode(java.lang.String s)
x-www-form-urlencoded
format.s
- String
to be translated.String
.private static java.lang.String _encode(java.lang.String s)
static java.lang.String decode(java.lang.String s)
s
- the String
to decodeString
private static int indexOfAny(java.lang.String s, java.lang.String any)
private static int indexOfAny(java.lang.String s, java.lang.String any, int start)