Skip to Main Content
JavaMail API
book

JavaMail API

by Elliotte Rusty Harold
July 2013
Intermediate to advanced content levelIntermediate to advanced
95 pages
2h 15m
English
O'Reilly Media, Inc.
Content preview from JavaMail API

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 java.net.URI 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://elharo:mypassword@mail.ibiblio.org:110/INBOX) that don’t have a matching protocol handler:

public class URLName Object

The methods of URLName are very similar to those of java.net.URL, 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 java.net.URL 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://eharold:password@utopia.poly.edu/INBOX or imap://elharo@ibiblio.org/Speaking/SD2008West. 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:

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Scripting in Java: Integrating with Groovy and JavaScript

Scripting in Java: Integrating with Groovy and JavaScript

Kishori Sharan
Spring Boot 2.0 Projects

Spring Boot 2.0 Projects

Mohamed Shazin Sadakath

Publisher Resources

ISBN: 9781449367237Errata Page