Java Reference
In-Depth Information
Address recHumorFunny = new NewsAddress ( "rec.humor.funny" ,
"nntp.aioe.org" );
There are eight instance methods in this class—three getter methods, two setter meth‐
ods, and three utility methods:
public String getType ()
public String getHost ()
public String getNewsgroup ()
public void setNewsgroup ( String newsgroup )
public void setHost ( String host )
public String toString ()
public boolean equals ( Object o )
public int hashCode ()
The setNewsgroup() and setHost() methods set the newsgroup and host fields of the
object to the specified values. The getNewsgroup() and getHost() methods return the
values of the newsgroup and host fields. Finally, the getType() method returns the
string “news”.
The toString() method returns the newsgroup name in a form suitable for the News‐
groups: header field of a Usenet posting. The equals() and hashCode() methods have
their usual semantics.
There are also two static utility methods for converting addresses to and from strings:
public static String toString ( Address [] addresses )
throws ClassCastException
public static NewsAddress [] parse ( String newsgroups )
throws AddressException
The toString() method converts an array of Address objects into a comma-separated
list of newsgroup names. A ClassCastException is thrown if any of the Address objects
in the array are not more specifically NewsAddress objects. The parse() method re‐
verses this operation, converting a comma-separated String of newsgroup names, such
as “comp.lang.java.programmer,comp.lang.java.gui,comp.lang.java.help”, into an array
of NewsAddress objects. It throws an AddressException if the newsgroups argument is
not a comma-separated list of newsgroup names.
The reference implementation of the JavaMail API does not include a service provider
for news, however; although you can create news addresses, before you can actually read
and post news you'll need to install a service provider that supports it. Table 1-1 lists
some possible sources of news providers. Once you've got one, reading news is as
straightforward as talking to an IMAP server.
Search WWH ::




Custom Search