public class NNTPClient extends NNTP
SocketClient
,
you must first connect to the server with
connect
before doing anything, and finally
disconnect()
after you're completely finished interacting with the server.
Remember that the
isAllowedToPost()
method is defined in
NNTP
.
You should keep in mind that the NNTP server may choose to prematurely
close a connection if the client has been idle for longer than a
given time period or if the server is being shutdown by the operator or
some other reason. The NNTP class will detect a
premature NNTP server connection closing when it receives a
NNTPReply.SERVICE_DISCONTINUED
response to a command.
When that occurs, the NNTP class method encountering that reply will throw
an NNTPConnectionClosedException
.
NNTPConectionClosedException
is a subclass of IOException
and therefore need not be
caught separately, but if you are going to catch it separately, its
catch block must appear before the more general IOException
catch block. When you encounter an
NNTPConnectionClosedException
, you must disconnect the connection with
disconnect()
to properly clean up the
system resources used by NNTP. Before disconnecting, you may check the
last reply code and text with
getReplyCode
and
getReplyString
.
Rather than list it separately for each method, we mention here that
every method communicating with the server and throwing an IOException
can also throw a
MalformedServerReplyException
, which is a subclass
of IOException. A MalformedServerReplyException will be thrown when
the reply received from the server deviates enough from the protocol
specification that it cannot be interpreted in a useful manner despite
attempts to be as lenient as possible.
_commandSupport_, _isAllowedToPost, _reader_, _replyCode, _replyString, _writer_, DEFAULT_PORT
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL
Constructor and Description |
---|
NNTPClient() |
Modifier and Type | Method and Description |
---|---|
private void |
__ai2ap(ArticleInfo ai,
ArticlePointer ap) |
private ArticleInfo |
__ap2ai(ArticlePointer ap) |
(package private) static Article |
__parseArticleEntry(java.lang.String line)
Parse a response line from
retrieveArticleInfo(long, long) . |
private void |
__parseArticlePointer(java.lang.String reply,
ArticleInfo pointer)
Parse the reply and store the id and number in the pointer.
|
private static void |
__parseGroupReply(java.lang.String reply,
NewsgroupInfo info) |
(package private) static NewsgroupInfo |
__parseNewsgroupListEntry(java.lang.String entry) |
private NewsgroupInfo[] |
__readNewsgroupListing() |
private java.io.BufferedReader |
__retrieve(int command,
long articleNumber,
ArticleInfo pointer) |
private java.io.BufferedReader |
__retrieve(int command,
java.lang.String articleId,
ArticleInfo pointer) |
private java.io.BufferedReader |
__retrieveArticleInfo(java.lang.String articleRange)
Private implementation of XOVER functionality.
|
private java.io.BufferedReader |
__retrieveHeader(java.lang.String header,
java.lang.String articleRange)
Private implementation of XHDR functionality.
|
boolean |
authenticate(java.lang.String username,
java.lang.String password)
Log into a news server by sending the AUTHINFO USER/AUTHINFO
PASS command sequence.
|
boolean |
completePendingCommand()
There are a few NNTPClient methods that do not complete the
entire sequence of NNTP commands to complete a transaction.
|
java.io.Writer |
forwardArticle(java.lang.String articleId) |
java.lang.Iterable<Article> |
iterateArticleInfo(long lowArticleNumber,
long highArticleNumber)
Return article headers for all articles between lowArticleNumber
and highArticleNumber, inclusively, using the XOVER command.
|
java.lang.Iterable<java.lang.String> |
iterateNewNews(NewGroupsOrNewsQuery query)
List all new articles added to the NNTP server since a particular
date subject to the conditions of the specified query.
|
java.lang.Iterable<java.lang.String> |
iterateNewNewsgroupListing(NewGroupsOrNewsQuery query)
List all new newsgroups added to the NNTP server since a particular
date subject to the conditions of the specified query.
|
java.lang.Iterable<NewsgroupInfo> |
iterateNewNewsgroups(NewGroupsOrNewsQuery query)
List all new newsgroups added to the NNTP server since a particular
date subject to the conditions of the specified query.
|
java.lang.Iterable<java.lang.String> |
iterateNewsgroupListing()
List all newsgroups served by the NNTP server.
|
java.lang.Iterable<java.lang.String> |
iterateNewsgroupListing(java.lang.String wildmat)
List the newsgroups that match a given pattern.
|
java.lang.Iterable<NewsgroupInfo> |
iterateNewsgroups()
List all newsgroups served by the NNTP server.
|
java.lang.Iterable<NewsgroupInfo> |
iterateNewsgroups(java.lang.String wildmat)
List the newsgroups that match a given pattern.
|
java.lang.String |
listHelp()
List the command help from the server.
|
java.lang.String[] |
listNewNews(NewGroupsOrNewsQuery query)
List all new articles added to the NNTP server since a particular
date subject to the conditions of the specified query.
|
NewsgroupInfo[] |
listNewNewsgroups(NewGroupsOrNewsQuery query)
List all new newsgroups added to the NNTP server since a particular
date subject to the conditions of the specified query.
|
NewsgroupInfo[] |
listNewsgroups()
List all newsgroups served by the NNTP server.
|
NewsgroupInfo[] |
listNewsgroups(java.lang.String wildmat)
List the newsgroups that match a given pattern.
|
java.lang.String[] |
listOverviewFmt()
Send a "LIST OVERVIEW.FMT" command to the server.
|
boolean |
logout()
Logs out of the news server gracefully by sending the QUIT command.
|
java.io.Writer |
postArticle()
Post an article to the NNTP server.
|
java.io.Reader |
retrieveArticle()
Same as
retrieveArticle((String) null)
Note: the return can be cast to a BufferedReader |
java.io.Reader |
retrieveArticle(int articleNumber)
Deprecated.
3.0 use
retrieveArticle(long) instead |
java.io.Reader |
retrieveArticle(int articleNumber,
ArticlePointer pointer)
Deprecated.
3.0 use
retrieveArticle(long, ArticleInfo) instead |
java.io.BufferedReader |
retrieveArticle(long articleNumber)
Same as
retrieveArticle(articleNumber, null) |
java.io.BufferedReader |
retrieveArticle(long articleNumber,
ArticleInfo pointer)
Retrieves an article from the currently selected newsgroup.
|
java.io.Reader |
retrieveArticle(java.lang.String articleId)
Same as
retrieveArticle(articleId, (ArticleInfo) null)
Note: the return can be cast to a BufferedReader |
java.io.BufferedReader |
retrieveArticle(java.lang.String articleId,
ArticleInfo pointer)
Retrieves an article from the NNTP server.
|
java.io.Reader |
retrieveArticle(java.lang.String articleId,
ArticlePointer pointer)
Deprecated.
3.0 use
retrieveArticle(String, ArticleInfo) instead |
java.io.Reader |
retrieveArticleBody()
Same as
retrieveArticleBody(null)
Note: the return can be cast to a BufferedReader |
java.io.Reader |
retrieveArticleBody(int a)
Deprecated.
3.0 use
retrieveArticleBody(long) instead |
java.io.Reader |
retrieveArticleBody(int a,
ArticlePointer ap)
Deprecated.
3.0 use
retrieveArticleBody(long, ArticleInfo) instead |
java.io.BufferedReader |
retrieveArticleBody(long articleNumber)
Same as
retrieveArticleBody(articleNumber, null) |
java.io.BufferedReader |
retrieveArticleBody(long articleNumber,
ArticleInfo pointer)
Retrieves an article body from the currently selected newsgroup.
|
java.io.Reader |
retrieveArticleBody(java.lang.String articleId)
Same as
retrieveArticleBody(articleId, (ArticleInfo) null)
Note: the return can be cast to a BufferedReader |
java.io.BufferedReader |
retrieveArticleBody(java.lang.String articleId,
ArticleInfo pointer)
Retrieves an article body from the NNTP server.
|
java.io.Reader |
retrieveArticleBody(java.lang.String articleId,
ArticlePointer pointer)
Deprecated.
3.0 use
retrieveArticleBody(String, ArticleInfo) instead |
java.io.Reader |
retrieveArticleHeader()
Same as
retrieveArticleHeader((String) null)
Note: the return can be cast to a BufferedReader |
java.io.Reader |
retrieveArticleHeader(int a)
Deprecated.
3.0 use
retrieveArticleHeader(long) instead |
java.io.Reader |
retrieveArticleHeader(int a,
ArticlePointer ap)
Deprecated.
3.0 use
retrieveArticleHeader(long, ArticleInfo) instead |
java.io.BufferedReader |
retrieveArticleHeader(long articleNumber)
Same as
retrieveArticleHeader(articleNumber, null) |
java.io.BufferedReader |
retrieveArticleHeader(long articleNumber,
ArticleInfo pointer)
Retrieves an article header from the currently selected newsgroup.
|
java.io.Reader |
retrieveArticleHeader(java.lang.String articleId)
Same as
retrieveArticleHeader(articleId, (ArticleInfo) null)
Note: the return can be cast to a BufferedReader |
java.io.BufferedReader |
retrieveArticleHeader(java.lang.String articleId,
ArticleInfo pointer)
Retrieves an article header from the NNTP server.
|
java.io.Reader |
retrieveArticleHeader(java.lang.String articleId,
ArticlePointer pointer)
Deprecated.
3.0 use
retrieveArticleHeader(String, ArticleInfo) instead |
java.io.Reader |
retrieveArticleInfo(int lowArticleNumber)
Deprecated.
3.0 use
retrieveArticleInfo(long) instead |
java.io.Reader |
retrieveArticleInfo(int lowArticleNumber,
int highArticleNumber)
Deprecated.
3.0 use
retrieveArticleInfo(long, long) instead |
java.io.BufferedReader |
retrieveArticleInfo(long articleNumber)
Return article headers for a specified post.
|
java.io.BufferedReader |
retrieveArticleInfo(long lowArticleNumber,
long highArticleNumber)
Return article headers for all articles between lowArticleNumber
and highArticleNumber, inclusively.
|
java.io.Reader |
retrieveHeader(java.lang.String a,
int b)
Deprecated.
3.0 use
retrieveHeader(String, long) instead |
java.io.Reader |
retrieveHeader(java.lang.String header,
int lowArticleNumber,
int highArticleNumber)
Deprecated.
3.0 use
retrieveHeader(String, long, long) instead |
java.io.BufferedReader |
retrieveHeader(java.lang.String header,
long articleNumber)
Return an article header for a specified post.
|
java.io.BufferedReader |
retrieveHeader(java.lang.String header,
long lowArticleNumber,
long highArticleNumber)
Return an article header for all articles between lowArticleNumber
and highArticleNumber, inclusively.
|
boolean |
selectArticle(ArticleInfo pointer)
Same as
selectArticle((String) null, articleId) . |
boolean |
selectArticle(ArticlePointer pointer)
Deprecated.
3.0 use
selectArticle(ArticleInfo) instead |
boolean |
selectArticle(int a)
Deprecated.
3.0 use
selectArticle(long) instead |
boolean |
selectArticle(int a,
ArticlePointer ap)
Deprecated.
3.0 use
selectArticle(long, ArticleInfo) instead |
boolean |
selectArticle(long articleNumber)
Same as
selectArticle(articleNumber, null) |
boolean |
selectArticle(long articleNumber,
ArticleInfo pointer)
Select an article in the currently selected newsgroup by its number.
|
boolean |
selectArticle(java.lang.String articleId)
Same as
selectArticle(articleId, (ArticleInfo) null) |
boolean |
selectArticle(java.lang.String articleId,
ArticleInfo pointer)
Select an article by its unique identifier (including enclosing
< and >) and return its article number and id through the
pointer parameter.
|
boolean |
selectArticle(java.lang.String articleId,
ArticlePointer pointer)
Deprecated.
3.0 use
selectArticle(String, ArticleInfo) instead |
boolean |
selectNewsgroup(java.lang.String newsgroup)
Same as
selectNewsgroup(newsgroup, null) |
boolean |
selectNewsgroup(java.lang.String newsgroup,
NewsgroupInfo info)
Select the specified newsgroup to be the target of for future article
retrieval and posting operations.
|
boolean |
selectNextArticle()
Same as
selectNextArticle((ArticleInfo) null) |
boolean |
selectNextArticle(ArticleInfo pointer)
Select the article following the currently selected article in the
currently selected newsgroup and return its number and unique id
through the pointer parameter.
|
boolean |
selectNextArticle(ArticlePointer pointer)
Deprecated.
3.0 use
selectNextArticle(ArticleInfo) instead |
boolean |
selectPreviousArticle()
Same as
selectPreviousArticle((ArticleInfo) null) |
boolean |
selectPreviousArticle(ArticleInfo pointer)
Select the article preceeding the currently selected article in the
currently selected newsgroup and return its number and unique id
through the pointer parameter.
|
boolean |
selectPreviousArticle(ArticlePointer pointer)
Deprecated.
3.0 use
selectPreviousArticle(ArticleInfo) instead |
_connectAction_, article, article, article, article, authinfoPass, authinfoUser, body, body, body, body, disconnect, getCommandSupport, getReply, getReplyCode, getReplyString, group, head, head, head, head, help, ihave, isAllowedToPost, last, list, listActive, newgroups, newnews, next, post, quit, sendCommand, sendCommand, sendCommand, sendCommand, stat, stat, stat, stat, xhdr, xover
addProtocolCommandListener, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, fireReplyReceived, getCharset, getCharsetName, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
private void __parseArticlePointer(java.lang.String reply, ArticleInfo pointer) throws MalformedServerReplyException
reply
- the reply to parse "22n nnn pointer
- the pointer to updateMalformedServerReplyException
- if response could not be parsedprivate static void __parseGroupReply(java.lang.String reply, NewsgroupInfo info) throws MalformedServerReplyException
MalformedServerReplyException
static NewsgroupInfo __parseNewsgroupListEntry(java.lang.String entry)
static Article __parseArticleEntry(java.lang.String line)
retrieveArticleInfo(long, long)
.line
- a response lineArticle
, if unparseable then isDummy()
will be true, and the subject will contain the raw info.private NewsgroupInfo[] __readNewsgroupListing() throws java.io.IOException
java.io.IOException
private java.io.BufferedReader __retrieve(int command, java.lang.String articleId, ArticleInfo pointer) throws java.io.IOException
java.io.IOException
private java.io.BufferedReader __retrieve(int command, long articleNumber, ArticleInfo pointer) throws java.io.IOException
java.io.IOException
public java.io.BufferedReader retrieveArticle(java.lang.String articleId, ArticleInfo pointer) throws java.io.IOException
articleId
field of the ArticleInfo cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not follow these requirements, your program will not work properly.
articleId
- The unique article identifier of the article to
retrieve. If this parameter is null, the currently selected
article is retrieved.pointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.Reader retrieveArticle(java.lang.String articleId) throws java.io.IOException
retrieveArticle(articleId, (ArticleInfo) null)
Note: the return can be cast to a BufferedReader
articleId
- the article id to retrievejava.io.IOException
- if an IO error occurspublic java.io.Reader retrieveArticle() throws java.io.IOException
retrieveArticle((String) null)
Note: the return can be cast to a BufferedReader
java.io.IOException
- if an IO error occurspublic java.io.BufferedReader retrieveArticle(long articleNumber, ArticleInfo pointer) throws java.io.IOException
articleId
field of the ArticleInfo cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not follow these requirements, your program will not work properly.
articleNumber
- The number of the the article to
retrieve.pointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.BufferedReader retrieveArticle(long articleNumber) throws java.io.IOException
retrieveArticle(articleNumber, null)
articleNumber
- the article number to fetchjava.io.IOException
- if an IO error occurspublic java.io.BufferedReader retrieveArticleHeader(java.lang.String articleId, ArticleInfo pointer) throws java.io.IOException
articleId
field of the ArticleInfo cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not follow these requirements, your program will not work properly.
articleId
- The unique article identifier of the article whose
header is being retrieved. If this parameter is null, the
header of the currently selected article is retrieved.pointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.Reader retrieveArticleHeader(java.lang.String articleId) throws java.io.IOException
retrieveArticleHeader(articleId, (ArticleInfo) null)
Note: the return can be cast to a BufferedReader
articleId
- the article id to fetchjava.io.IOException
- if an error occurspublic java.io.Reader retrieveArticleHeader() throws java.io.IOException
retrieveArticleHeader((String) null)
Note: the return can be cast to a BufferedReader
java.io.IOException
- if an error occurspublic java.io.BufferedReader retrieveArticleHeader(long articleNumber, ArticleInfo pointer) throws java.io.IOException
articleId
field of the ArticleInfo cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not follow these requirements, your program will not work properly.
articleNumber
- The number of the the article whose header is
being retrieved.pointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.BufferedReader retrieveArticleHeader(long articleNumber) throws java.io.IOException
retrieveArticleHeader(articleNumber, null)
articleNumber
- the article numberjava.io.IOException
- if an error occurspublic java.io.BufferedReader retrieveArticleBody(java.lang.String articleId, ArticleInfo pointer) throws java.io.IOException
articleId
field of the ArticleInfo cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not follow these requirements, your program will not work properly.
articleId
- The unique article identifier of the article whose
body is being retrieved. If this parameter is null, the
body of the currently selected article is retrieved.pointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.Reader retrieveArticleBody(java.lang.String articleId) throws java.io.IOException
retrieveArticleBody(articleId, (ArticleInfo) null)
Note: the return can be cast to a BufferedReader
articleId
- the article idjava.io.IOException
- if an error occurspublic java.io.Reader retrieveArticleBody() throws java.io.IOException
retrieveArticleBody(null)
Note: the return can be cast to a BufferedReader
java.io.IOException
- if an error occurspublic java.io.BufferedReader retrieveArticleBody(long articleNumber, ArticleInfo pointer) throws java.io.IOException
articleId
field of the ArticleInfo cannot always be trusted because some
NNTP servers do not correctly follow the RFC 977 reply format.
A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned.
You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not follow these requirements, your program will not work properly.
articleNumber
- The number of the the article whose body is
being retrieved.pointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.BufferedReader retrieveArticleBody(long articleNumber) throws java.io.IOException
retrieveArticleBody(articleNumber, null)
articleNumber
- the article numberjava.io.IOException
- if an error occurspublic boolean selectNewsgroup(java.lang.String newsgroup, NewsgroupInfo info) throws java.io.IOException
newsgroup
- The newsgroup to select.info
- A parameter through which the newsgroup information of
the selected newsgroup contained in the server reply is returned.
Set this to null if you do not desire this information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean selectNewsgroup(java.lang.String newsgroup) throws java.io.IOException
selectNewsgroup(newsgroup, null)
newsgroup
- the newsgroup namejava.io.IOException
- if an error occurspublic java.lang.String listHelp() throws java.io.IOException
NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String[] listOverviewFmt() throws java.io.IOException
null
if the command failedjava.io.IOException
- on errorpublic boolean selectArticle(java.lang.String articleId, ArticleInfo pointer) throws java.io.IOException
articleId
- The unique article identifier of the article that
is being selectedd. If this parameter is null, the
body of the current article is selectedpointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean selectArticle(java.lang.String articleId) throws java.io.IOException
selectArticle(articleId, (ArticleInfo) null)
articleId
- the article Idjava.io.IOException
- on errorpublic boolean selectArticle(ArticleInfo pointer) throws java.io.IOException
selectArticle((String) null, articleId)
. Useful
for retrieving the current article number.pointer
- to the articlejava.io.IOException
- on errorpublic boolean selectArticle(long articleNumber, ArticleInfo pointer) throws java.io.IOException
articleNumber
- The number of the article to select from the
currently selected newsgroup.pointer
- A parameter through which to return the article's
number and unique id. Although the articleId field cannot always
be trusted because of server deviations from RFC 977 reply formats,
we haven't found a server that misformats this information in response
to this particular command. You may set this parameter to null if
you do not desire to retrieve the returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean selectArticle(long articleNumber) throws java.io.IOException
selectArticle(articleNumber, null)
articleNumber
- the numgerjava.io.IOException
- on errorpublic boolean selectPreviousArticle(ArticleInfo pointer) throws java.io.IOException
selectArticle(pointer.articleNumber, pointer)
immediately
afterward.
pointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean selectPreviousArticle() throws java.io.IOException
selectPreviousArticle((ArticleInfo) null)
java.io.IOException
- on errorpublic boolean selectNextArticle(ArticleInfo pointer) throws java.io.IOException
selectArticle(pointer.articleNumber, pointer)
immediately
afterward.
pointer
- A parameter through which to return the article's
number and unique id. The articleId field cannot always be trusted
because of server deviations from RFC 977 reply formats. You may
set this parameter to null if you do not desire to retrieve the
returned article information.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean selectNextArticle() throws java.io.IOException
selectNextArticle((ArticleInfo) null)
java.io.IOException
- on errorpublic NewsgroupInfo[] listNewsgroups() throws java.io.IOException
NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.iterateNewsgroupListing()
,
iterateNewsgroups()
public java.lang.Iterable<java.lang.String> iterateNewsgroupListing() throws java.io.IOException
NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.Iterable<NewsgroupInfo> iterateNewsgroups() throws java.io.IOException
NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public NewsgroupInfo[] listNewsgroups(java.lang.String wildmat) throws java.io.IOException
wildmat
- a pseudo-regex pattern (cf. RFC 2980)java.io.IOException
- on erroriterateNewsgroupListing(String)
,
iterateNewsgroups(String)
public java.lang.Iterable<java.lang.String> iterateNewsgroupListing(java.lang.String wildmat) throws java.io.IOException
wildmat
- a pseudo-regex pattern (cf. RFC 2980)java.io.IOException
- on errorpublic java.lang.Iterable<NewsgroupInfo> iterateNewsgroups(java.lang.String wildmat) throws java.io.IOException
wildmat
- a pseudo-regex pattern (cf. RFC 2980)java.io.IOException
- on errorpublic NewsgroupInfo[] listNewNewsgroups(NewGroupsOrNewsQuery query) throws java.io.IOException
query
- The query restricting how to search for new newsgroups.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.iterateNewNewsgroups(NewGroupsOrNewsQuery)
,
iterateNewNewsgroupListing(NewGroupsOrNewsQuery)
public java.lang.Iterable<java.lang.String> iterateNewNewsgroupListing(NewGroupsOrNewsQuery query) throws java.io.IOException
query
- The query restricting how to search for new newsgroups.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.Iterable<NewsgroupInfo> iterateNewNewsgroups(NewGroupsOrNewsQuery query) throws java.io.IOException
query
- The query restricting how to search for new newsgroups.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String[] listNewNews(NewGroupsOrNewsQuery query) throws java.io.IOException
query
- The query restricting how to search for new news. You
must add at least one newsgroup to the query.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.iterateNewNews(NewGroupsOrNewsQuery)
public java.lang.Iterable<java.lang.String> iterateNewNews(NewGroupsOrNewsQuery query) throws java.io.IOException
query
- The query restricting how to search for new news. You
must add at least one newsgroup to the query.NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean completePendingCommand() throws java.io.IOException
For example
writer = client.postArticle(); if(writer == null) // failure return false; header = new SimpleNNTPHeader("foobar@foo.com", "Just testing"); header.addNewsgroup("alt.test"); writer.write(header.toString()); writer.write("This is just a test"); writer.close(); if(!client.completePendingCommand()) // failure return false;
NNTPConnectionClosedException
- If the NNTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send NNTP reply code 400. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.Writer postArticle() throws java.io.IOException
isAllowedToPost()
before trying to post. However, a posting
attempt can fail due to malformed headers.
You must not issue any commands to the NNTP server (i.e., call any (other methods) until you finish writing to the returned Writer instance and close it. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned Writer actually writes directly to the NNTP connection. After you close the writer, you can execute new commands. If you do not follow these requirements your program will not work properly.
Different NNTP servers will require different header formats, but
you can use the provided
SimpleNNTPHeader
class to construct the bare minimum acceptable header for most
news readers. To construct more complicated headers you should
refer to RFC 822. When the Java Mail API is finalized, you will be
able to use it to compose fully compliant Internet text messages.
The DotTerminatedMessageWriter takes care of doubling line-leading
dots and ending the message with a single dot upon closing, so all
you have to worry about is writing the header and the message.
Upon closing the returned Writer, you need to call
completePendingCommand()
to finalize the posting and verify its success or failure from
the server reply.
java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.Writer forwardArticle(java.lang.String articleId) throws java.io.IOException
java.io.IOException
public boolean logout() throws java.io.IOException
java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean authenticate(java.lang.String username, java.lang.String password) throws java.io.IOException
username
- a valid usernamepassword
- the corresponding passwordjava.io.IOException
- on errorprivate java.io.BufferedReader __retrieveArticleInfo(java.lang.String articleRange) throws java.io.IOException
NNTP.xover(java.lang.String)
for legal agument formats. Alternatively, read RFC 2980 :-)
articleRange
- java.io.IOException
public java.io.BufferedReader retrieveArticleInfo(long articleNumber) throws java.io.IOException
articleNumber
- the article to retrieve headers forjava.io.IOException
- on errorpublic java.io.BufferedReader retrieveArticleInfo(long lowArticleNumber, long highArticleNumber) throws java.io.IOException
lowArticleNumber
- low numberhighArticleNumber
- high numberjava.io.IOException
- on errorpublic java.lang.Iterable<Article> iterateArticleInfo(long lowArticleNumber, long highArticleNumber) throws java.io.IOException
lowArticleNumber
- lowhighArticleNumber
- highjava.io.IOException
- if the command failedprivate java.io.BufferedReader __retrieveHeader(java.lang.String header, java.lang.String articleRange) throws java.io.IOException
NNTP.xhdr(java.lang.String, java.lang.String)
for legal agument formats. Alternatively, read RFC 1036.
header
- articleRange
- java.io.IOException
public java.io.BufferedReader retrieveHeader(java.lang.String header, long articleNumber) throws java.io.IOException
header
- the header to retrievearticleNumber
- the article to retrieve the header forjava.io.IOException
- on errorpublic java.io.BufferedReader retrieveHeader(java.lang.String header, long lowArticleNumber, long highArticleNumber) throws java.io.IOException
header
- the headerlowArticleNumber
- to fetchhighArticleNumber
- to fetchjava.io.IOException
- on error@Deprecated public java.io.Reader retrieveHeader(java.lang.String header, int lowArticleNumber, int highArticleNumber) throws java.io.IOException
retrieveHeader(String, long, long)
insteadheader
- the headerlowArticleNumber
- to fetchhighArticleNumber
- to fetchjava.io.IOException
- on error@Deprecated public java.io.Reader retrieveArticleInfo(int lowArticleNumber, int highArticleNumber) throws java.io.IOException
retrieveArticleInfo(long, long)
insteadlowArticleNumber
- to fetchhighArticleNumber
- to fetchjava.io.IOException
- on error@Deprecated public java.io.Reader retrieveHeader(java.lang.String a, int b) throws java.io.IOException
retrieveHeader(String, long)
insteada
- tbab
- tbajava.io.IOException
- tba@Deprecated public boolean selectArticle(int a, ArticlePointer ap) throws java.io.IOException
selectArticle(long, ArticleInfo)
insteada
- tbaap
- tbajava.io.IOException
- tba@Deprecated public java.io.Reader retrieveArticleInfo(int lowArticleNumber) throws java.io.IOException
retrieveArticleInfo(long)
insteadlowArticleNumber
- to fetchjava.io.IOException
- tba@Deprecated public boolean selectArticle(int a) throws java.io.IOException
selectArticle(long)
insteada
- tbajava.io.IOException
- tba@Deprecated public java.io.Reader retrieveArticleHeader(int a) throws java.io.IOException
retrieveArticleHeader(long)
insteada
- tbajava.io.IOException
- tba@Deprecated public java.io.Reader retrieveArticleHeader(int a, ArticlePointer ap) throws java.io.IOException
retrieveArticleHeader(long, ArticleInfo)
insteada
- tbaap
- tbajava.io.IOException
- tba@Deprecated public java.io.Reader retrieveArticleBody(int a) throws java.io.IOException
retrieveArticleBody(long)
insteada
- tbajava.io.IOException
- tba@Deprecated public java.io.Reader retrieveArticle(int articleNumber, ArticlePointer pointer) throws java.io.IOException
retrieveArticle(long, ArticleInfo)
insteadarticleNumber
- The number of the the article to retrieve.pointer
- A parameter through which to return the article's number and unique idjava.io.IOException
- on error@Deprecated public java.io.Reader retrieveArticle(int articleNumber) throws java.io.IOException
retrieveArticle(long)
insteadarticleNumber
- The number of the the article to retrievejava.io.IOException
- on error@Deprecated public java.io.Reader retrieveArticleBody(int a, ArticlePointer ap) throws java.io.IOException
retrieveArticleBody(long, ArticleInfo)
insteada
- tbaap
- tbajava.io.IOException
- tba@Deprecated public java.io.Reader retrieveArticle(java.lang.String articleId, ArticlePointer pointer) throws java.io.IOException
retrieveArticle(String, ArticleInfo)
insteadarticleId
- The unique article identifier of the article to retrievepointer
- A parameter through which to return the article's number and unique idjava.io.IOException
- on error@Deprecated public java.io.Reader retrieveArticleBody(java.lang.String articleId, ArticlePointer pointer) throws java.io.IOException
retrieveArticleBody(String, ArticleInfo)
insteadarticleId
- The unique article identifier of the article to retrievepointer
- A parameter through which to return the article's number and unique idjava.io.IOException
- on error@Deprecated public java.io.Reader retrieveArticleHeader(java.lang.String articleId, ArticlePointer pointer) throws java.io.IOException
retrieveArticleHeader(String, ArticleInfo)
insteadarticleId
- The unique article identifier of the article to retrievepointer
- A parameter through which to return the article's number and unique idjava.io.IOException
- on error@Deprecated public boolean selectArticle(java.lang.String articleId, ArticlePointer pointer) throws java.io.IOException
selectArticle(String, ArticleInfo)
insteadarticleId
- The unique article identifier of the article to retrievepointer
- A parameter through which to return the article's number and unique idjava.io.IOException
- on error@Deprecated public boolean selectArticle(ArticlePointer pointer) throws java.io.IOException
selectArticle(ArticleInfo)
insteadpointer
- A parameter through which to return the article's number and unique idjava.io.IOException
- on error@Deprecated public boolean selectNextArticle(ArticlePointer pointer) throws java.io.IOException
selectNextArticle(ArticleInfo)
insteadpointer
- A parameter through which to return the article's number and unique idjava.io.IOException
- on error@Deprecated public boolean selectPreviousArticle(ArticlePointer pointer) throws java.io.IOException
selectPreviousArticle(ArticleInfo)
insteadpointer
- A parameter through which to return the article's number and unique idjava.io.IOException
- on errorprivate ArticleInfo __ap2ai(ArticlePointer ap)
private void __ai2ap(ArticleInfo ai, ArticlePointer ap)