Chapter 6. The URLName Class

javax.mail.URLName treats a URL as a string, but does not attempt to connect to or resolve any of the parts of the string. It’s conceptually similar to but predates it by several years.

URL names are mainly used as convenient ways to identify folders and stores with nonstandard URLs (such as pop3:// that don’t have a matching protocol handler:

public class URLName Object

The methods of URLName are very similar to those of, except that all those involving actual connections have been deleted. What’s left is a bunch of methods for breaking a URL string into its component parts or building a URL from pieces.

The Constructors

There are three overloaded URLName constructors. One takes the individual pieces of a URL as arguments, another takes a object, and a third takes a String containing a URL:

public URLName(String protocol, String host, int port, String file,
    String userName, String password)
public URLName(URL url)
public URLName(String url)

All the operations on the URLName take place with simple substring manipulation, allowing the URLName class to support nonstandard URLs such as pop3:// or imap:// These URLName objects can be used to refer to particular folders on the server.

Parsing Methods

These seven getter methods are the main purpose for this class. They return individual pieces of the URL:

Get JavaMail API now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.