Top Description Fields Constructors Methods
javax.mail

public Class URLName

extends Object
Class Inheritance
Imports
java.net.*, java.io.ByteArrayOutputStream, .OutputStreamWriter, .IOException, .UnsupportedEncodingException, java.util.BitSet, .Locale

The 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.URL in that this class just represents the name of a URL, it does not model the connection to a URL.

Authors
Christopher Cotton, Bill Shannon

Field Summary

Modifier and TypeField and Description
pack-priv static final int
private static boolean
doEncode

A way to turn off encoding, just in case...

pack-priv static BitSet
dontNeedEncoding

The class contains a utility method for converting a String into a MIME format called "x-www-form-urlencoded" format.

private String
file

The specified file name on that host.

protected String
fullURL

The full version of the URL

private int
hashCode

Our hash code.

private String
host

The host name to which to connect.

private InetAddress
hostAddress

The host's IP address, used in equals and hashCode.

private boolean
private String
password

The password to use when connecting.

private int
port

The protocol port to connect to.

private String
protocol

The protocol to use (ftp, http, nntp, imap, pop3 ...

private String
ref

# reference.

private String
username

The username to use when connecting

Constructor Summary

AccessConstructor and Description
public
URLName(String
the protocol
protocol
,
String
the host name
host
,
int
the port number
port
,
String
the file
file
,
String
the user name
username
,
String
the password
password
)

Creates a URLName object from the specified protocol, host, port number, file, username, and password.

public
URLName(URL
the URL
url
)

Construct a URLName from a java.net.URL object.

public
URLName(String
the URL string
url
)

Construct a URLName from the string.

Method Summary

Modifier and TypeMethod and Description
private static String
pack-priv static String

Returns:

the newly decoded String
decode
(String
the String to decode
s
)

Decodes a "x-www-form-urlencoded" to a String.

pack-priv static String

Returns:

the translated String.
encode
(String
String to be translated.
s
)

Translates a string into x-www-form-urlencoded format.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Compares two URLNames.
public String

Returns:

the file name of this URLName
getFile
()

Returns the file name of this URLName.

public String

Returns:

the host name
getHost
()

Returns the host of this URLName.

private synchronized InetAddress
getHostAddress()

Get the IP address of our host.

public String

Returns:

the password
getPassword
()

Returns the password of this URLName.

public int

Returns:

the port number
getPort
()

Returns the port number of this URLName.

public String

Returns:

the protocol
getProtocol
()

Returns the protocol of this URLName.

public String

Returns:

the reference part of the URLName
getRef
()

Returns the reference of this URLName.

public URL

Returns:

the URL
getURL
()

Constructs a URL from the URLName.

public String

Returns:

the user name
getUsername
()

Returns the user name of this URLName.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Compute the hash code for this URLName.
private static int
indexOfAny(String s, 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(String s, String any, int start)

protected void
parseString(String
the URL string to parse
url
)

Method which does all of the work of parsing the string.

public String
toString()

Overrides java.lang.Object.toString.

Constructs a string representation of this URLName.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

caseDiffback to summary
pack-priv static final int caseDiff
doEncodeback to summary
private static boolean doEncode

A way to turn off encoding, just in case...

dontNeedEncodingback to summary
pack-priv static BitSet dontNeedEncoding

The class contains a utility method for converting a String into 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.
Author
Herb Jellinek
Since
JDK1.0
fileback to summary
private String file

The specified file name on that host.

fullURLback to summary
protected String fullURL

The full version of the URL

hashCodeback to summary
private int hashCode

Our hash code.

hostback to summary
private String host

The host name to which to connect.

hostAddressback to summary
private InetAddress hostAddress

The host's IP address, used in equals and hashCode. Computed on demand.

hostAddressKnownback to summary
private boolean hostAddressKnown
passwordback to summary
private String password

The password to use when connecting.

portback to summary
private int port

The protocol port to connect to.

protocolback to summary
private String protocol

The protocol to use (ftp, http, nntp, imap, pop3 ... etc.) .

refback to summary
private String ref

# reference.

usernameback to summary
private String username

The username to use when connecting

Constructor Detail

URLNameback to summary
public URLName(String protocol, String host, int port, String file, String username, 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:String

the protocol

host:String

the host name

port:int

the port number

file:String

the file

username:String

the user name

password:String

the password

URLNameback to summary
public URLName(URL url)

Construct a URLName from a java.net.URL object.

Parameters
url:URL

the URL

URLNameback to summary
public URLName(String url)

Construct a URLName from the string. Parses out all the possible information (protocol, host, port, file, username, password).

Parameters
url:String

the URL string

Method Detail

_encodeback to summary
private static String _encode(String s)
decodeback to summary
pack-priv static String decode(String s)

Decodes a "x-www-form-urlencoded" to a String.

Parameters
s:String

the String to decode

Returns:String

the newly decoded String

encodeback to summary
pack-priv static String encode(String s)

Translates a string into x-www-form-urlencoded format.

Parameters
s:String

String to be translated.

Returns:String

the translated String.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

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.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getFileback to summary
public String getFile()

Returns the file name of this URLName. Returns null if this URLName has no file name.

Returns:String

the file name of this URLName

getHostback to summary
public String getHost()

Returns the host of this URLName. Returns null if this URLName has no host.

Returns:String

the host name

getHostAddressback to summary
private synchronized 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.

getPasswordback to summary
public String getPassword()

Returns the password of this URLName. Returns null if this URLName has no password.

Returns:String

the password

getPortback to summary
public int getPort()

Returns the port number of this URLName. Returns -1 if the port is not set.

Returns:int

the port number

getProtocolback to summary
public String getProtocol()

Returns the protocol of this URLName. Returns null if this URLName has no protocol.

Returns:String

the protocol

getRefback to summary
public String getRef()

Returns the reference of this URLName. Returns null if this URLName has no reference.

Returns:String

the reference part of the URLName

getURLback to summary
public URL getURL() throws MalformedURLException

Constructs a URL from the URLName.

Returns:URL

the URL

Exceptions
MalformedURLException:
if the URL is malformed
getUsernameback to summary
public String getUsername()

Returns the user name of this URLName. Returns null if this URLName has no user name.

Returns:String

the user name

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Compute the hash code for this URLName.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override
indexOfAnyback to summary
private static int indexOfAny(String s, 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.

indexOfAnyback to summary
private static int indexOfAny(String s, String any, int start)
parseStringback to summary
protected void parseString(String url)

Method which does all of the work of parsing the string.

Parameters
url:String

the URL string to parse

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Constructs a string representation of this URLName.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override