An NNTP client.
This object is used to establish and manage a connection to an NNTP
server.
article
public ArticleResponse article(int articleNumber)
throws IOException
Send an article retrieval request to the server.
articleNumber
- the article number of the article to retrieve
- an article response consisting of the article number and
message-id, and an iterator over the lines of the article header and
body, separated by an empty line
article
public ArticleResponse article(String messageId)
throws IOException
Send an article retrieval request to the server.
messageId
- the message-id of the article to retrieve
- an article response consisting of the article number and
message-id, and an iterator over the lines of the article header and
body, separated by an empty line
articleImpl
protected ArticleResponse articleImpl(String command,
String messageId)
throws IOException
Performs an ARTICLE, BODY, HEAD, or STAT command.
command
- one of the above commandsmessageId
- the article-number or message-id in string form
authinfo
public boolean authinfo(String username,
String password)
throws IOException
Basic authentication strategy.
username
- the user to authenticatepassword
- the(cleartext) password
- true on success, false on failure
authinfoGeneric
public boolean authinfoGeneric(String mechanism,
String username,
String password)
throws IOException
Authenticates the connection using the specified SASL mechanism,
username and password.
mechanism
- a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername
- the authentication principalpassword
- the authentication credentials
authinfoSimple
public boolean authinfoSimple(String username,
String password)
throws IOException
Implementation of NNTP simple authentication.
Note that use of this authentication strategy is highly deprecated,
only use on servers that won't accept any other form of authentication.
body
public ArticleResponse body(int articleNumber)
throws IOException
Send an article body retrieval request to the server.
articleNumber
- the article number of the article to body
- an article response consisting of the article number and
message-id, and an iterator over the lines of the article body
body
public ArticleResponse body(String messageId)
throws IOException
Send an article body retrieval request to the server.
messageId
- the message-id of the article to body
- an article response consisting of the article number and
message-id, and an iterator over the lines of the article body
getWelcome
public String getWelcome()
Return the welcome message sent by the server in reply to the initial
connection.
This message sometimes contains disclaimers or help information that
may be relevant to the user.
group
public GroupResponse group(String name)
throws IOException
Send a group selection command to the server.
Returns a group status response.
name
- the name of the group to select
head
public ArticleResponse head(int articleNumber)
throws IOException
Send an article head retrieval request to the server.
articleNumber
- the article number of the article to head
- an article response consisting of the article number and
message-id, and an iterator over the lines of the article header
head
public ArticleResponse head(String messageId)
throws IOException
Send an article head retrieval request to the server.
messageId
- the message-id of the article to head
- an article response consisting of the article number and
message-id, and an iterator over the lines of the article header
ihave
public PostStream ihave(String messageId)
throws IOException
Sends an ihave command indicating that the client has an article with
the specified message-id.
messageId
- the article message-id
- a PostStream if the server wants the specified article, null
otherwise
last
public ArticleResponse last()
throws IOException
Sends a previous article positioning command to the server.
- the article number/message-id pair associated with the new
article
list
public GroupIterator list()
throws IOException
Send a group listing command to the server.
Returns a GroupIterator. This must be read fully before other commands
are issued.
listActive
public GroupIterator listActive(String wildmat)
throws IOException
Returns an iterator over the groups specified according to the wildmat
pattern. The iterator must be read fully before other commands are
issued.
wildmat
- the wildmat pattern. If null, returns all groups. If no
groups are matched, returns an empty iterator.
listGroup
public ArticleNumberIterator listGroup(String group)
throws IOException
Returns a listing of all the article numbers in the specified
newsgroup. If the group
parameter is null, the currently
selected group is assumed.
group
- the name of the group to list articles for
listNewsgroups
public PairIterator listNewsgroups(String wildmat)
throws IOException
Returns an iterator over the group descriptions for the given groups.
wildmat
- if non-null, limits the groups in the iterator to the
specified pattern
- an iterator over group name/description pairs
xgtitle(String)
modeReader
public boolean modeReader()
throws IOException
Indicates to the server that this is a user-agent.
- true if posting is allowed, false otherwise.
modeStream
public boolean modeStream()
throws IOException
Attempt to initialise the connection in streaming mode.
This is generally used to bypass the lock step nature of NNTP in order
to perform a series of CHECK and TAKETHIS commands.
- true if the server supports streaming mode
newGroups
public LineIterator newGroups(Date since,
String[] distributions)
throws IOException
Returns an iterator over the list of new groups on the server since the
specified date.
NB this method suffers from a minor millenium bug.
since
- the date from which to list new groupsdistributions
- if non-null, an array of distributions to match
newNews
public LineIterator newNews(String newsgroup,
Date since,
String[] distributions)
throws IOException
Returns an iterator over the list of message-ids posted or received to
the specified newsgroup(s) since the specified date.
NB this method suffers from a minor millenium bug.
newsgroup
- the newsgroup wildmatsince
- the date from which to list new articlesdistributions
- if non-null, a list of distributions to match
next
public ArticleResponse next()
throws IOException
Sends a next article positioning command to the server.
- the article number/message-id pair associated with the new
article
post
public OutputStream post()
throws IOException
Post an article. This is a two-stage process.
If successful, returns an output stream to write the article to.
Clients should call write()
on the stream for all the
bytes of the article, and finally call close()
on the stream.
No other method should be called in between.
NNTPConnection
quit
public void quit()
throws IOException
Close the connection.
After calling this method, no further calls on this object are valid.
send
protected void send(String line)
throws IOException
Send a single line to the server.
line
- the line to send
slave
public void slave()
throws IOException
Indicates to the server that this is a slave connection.
stat
public ArticleResponse stat(int articleNumber)
throws IOException
Send an article status request to the server.
articleNumber
- the article number of the article to stat
- an article response consisting of the article number and
message-id
stat
public ArticleResponse stat(String messageId)
throws IOException
Send an article status request to the server.
messageId
- the message-id of the article to stat
- an article response consisting of the article number and
message-id
takethis
public OutputStream takethis(String messageId)
throws IOException
Implements the out-of-order takethis command.
The client uses the returned output stream to write all the bytes of the
article. When complete, it calls close()
on the
stream.
NNTPConnection
* NNTPConnection.java
* Copyright (C) 2002 The Free Software Foundation
*
* This file is part of GNU inetlib, a library.
*
* GNU inetlib is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GNU inetlib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Linking this library statically or dynamically with other modules is
* making a combined work based on this library. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* As a special exception, the copyright holders of this library give you
* permission to link this library with independent modules to produce an
* executable, regardless of the license terms of these independent
* modules, and to copy and distribute the resulting executable under
* terms of your choice, provided that you also meet, for each linked
* independent module, the terms and conditions of the license of that
* module. An independent module is a module which is not derived from
* or based on this library. If you modify this library, you may extend
* this exception to your version of the library, but you are not
* obliged to do so. If you do not wish to do so, delete this
* exception statement from your version.