|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.net.SocketClient org.apache.commons.net.nntp.NNTP
public class NNTP
The NNTP class is not meant to be used by itself and is provided
only so that you may easily implement your own NNTP client if
you so desire. If you have no need to perform your own implementation,
you should use NNTPClient
.
The NNTP class is made public to provide access to various NNTP constants
and to make it easier for adventurous programmers (or those with special
needs) to interact with the NNTP protocol and implement their own clients.
A set of methods with names corresponding to the NNTP command names are
provided to facilitate this interaction.
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.
NNTPClient
,
NNTPConnectionClosedException
,
MalformedServerReplyException
Field Summary | |
---|---|
protected ProtocolCommandSupport |
_commandSupport_
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents. |
protected BufferedReader |
_reader_
Wraps SocketClient._input_
to communicate with server. |
protected BufferedWriter |
_writer_
Wraps SocketClient._output_
to communicate with server. |
static int |
DEFAULT_PORT
The default NNTP port. |
Fields inherited from class org.apache.commons.net.SocketClient |
---|
_defaultPort_, _input_, _isConnected_, _output_, _socket_, _socketFactory_, _timeout_, NETASCII_EOL |
Constructor Summary | |
---|---|
NNTP()
The default NNTP constructor. |
Method Summary | |
---|---|
protected void |
_connectAction_()
Initiates control connections and gets initial reply, determining if the client is allowed to post to the server. |
void |
addProtocolCommandListener(ProtocolCommandListener listener)
Adds a ProtocolCommandListener. |
int |
article()
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code. |
int |
article(int articleNumber)
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code. |
int |
article(String messageId)
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code. |
int |
authinfoPass(String password)
A convenience method to send the AUTHINFO PASS command to the server, receive the reply, and return the reply code. |
int |
authinfoUser(String username)
A convenience method to send the AUTHINFO USER command to the server, receive the reply, and return the reply code. |
int |
body()
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code. |
int |
body(int articleNumber)
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code. |
int |
body(String messageId)
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code. |
void |
disconnect()
Closes the connection to the NNTP server and sets to null some internal data so that the memory may be reclaimed by the garbage collector. |
int |
getReply()
Fetches a reply from the NNTP server and returns the integer reply code. |
int |
getReplyCode()
Returns the integer value of the reply code of the last NNTP reply. |
String |
getReplyString()
Returns the entire text of the last NNTP server response exactly as it was received, not including the end of line marker. |
int |
group(String newsgroup)
A convenience method to send the NNTP GROUP command to the server, receive the reply, and return the reply code. |
int |
head()
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code. |
int |
head(int articleNumber)
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code. |
int |
head(String messageId)
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code. |
int |
help()
A convenience method to send the NNTP HELP command to the server, receive the reply, and return the reply code. |
int |
ihave(String messageId)
A convenience method to send the NNTP IHAVE command to the server, receive the reply, and return the reply code. |
boolean |
isAllowedToPost()
Indicates whether or not the client is allowed to post articles to the server it is currently connected to. |
int |
last()
A convenience method to send the NNTP LAST command to the server, receive the reply, and return the reply code. |
int |
list()
A convenience method to send the NNTP LIST command to the server, receive the reply, and return the reply code. |
int |
listActive(String wildmat)
A convenience wrapper for the extended LIST command that takes an argument, allowing us to selectively list multiple groups. |
int |
newgroups(String date,
String time,
boolean GMT,
String distributions)
A convenience method to send the NNTP NEWGROUPS command to the server, receive the reply, and return the reply code. |
int |
newnews(String newsgroups,
String date,
String time,
boolean GMT,
String distributions)
A convenience method to send the NNTP NEWGROUPS command to the server, receive the reply, and return the reply code. |
int |
next()
A convenience method to send the NNTP NEXT command to the server, receive the reply, and return the reply code. |
int |
post()
A convenience method to send the NNTP POST command to the server, receive the reply, and return the reply code. |
int |
quit()
A convenience method to send the NNTP QUIT command to the server, receive the reply, and return the reply code. |
void |
removeProtocolCommandListener(ProtocolCommandListener listener)
Removes a ProtocolCommandListener. |
int |
sendCommand(int command)
Sends an NNTP command with no arguments to the server, waits for a reply and returns the numerical response code. |
int |
sendCommand(int command,
String args)
Sends an NNTP command to the server, waits for a reply and returns the numerical response code. |
int |
sendCommand(String command)
Sends an NNTP command with no arguments to the server, waits for a reply and returns the numerical response code. |
int |
sendCommand(String command,
String args)
Sends an NNTP command to the server, waits for a reply and returns the numerical response code. |
int |
stat()
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code. |
int |
stat(int articleNumber)
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code. |
int |
stat(String messageId)
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code. |
int |
xhdr(String header,
String selectedArticles)
A convenience method to send the NNTP XHDR command to the server, receive the reply, and return the reply code. |
int |
xover(String selectedArticles)
A convenience method to send the NNTP XOVER command to the server, receive the reply, and return the reply code. |
Methods inherited from class org.apache.commons.net.SocketClient |
---|
connect, connect, connect, connect, connect, connect, getDefaultPort, getDefaultTimeout, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSoLinger, getSoTimeout, getTcpNoDelay, isConnected, setDefaultPort, setDefaultTimeout, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_PORT
protected BufferedReader _reader_
SocketClient._input_
to communicate with server. Initialized by _connectAction_()
.
All server reads should be done through this variable.
protected BufferedWriter _writer_
SocketClient._output_
to communicate with server. Initialized by _connectAction_()
.
All server reads should be done through this variable.
protected ProtocolCommandSupport _commandSupport_
Constructor Detail |
---|
public NNTP()
DEFAULT_PORT
and initializes internal data structures
for saving NNTP reply information.
Method Detail |
---|
protected void _connectAction_() throws IOException
_reader_
and _writer_
to wrap
SocketClient._input_
and SocketClient._output_
.
_connectAction_
in class SocketClient
IOException
public void addProtocolCommandListener(ProtocolCommandListener listener)
_commandSupport_
.
listener
- The ProtocolCommandListener to add.public void removeProtocolCommandListener(ProtocolCommandListener listener)
_commandSupport_
.
listener
- The ProtocolCommandListener to remove.public void disconnect() throws IOException
disconnect
in class SocketClient
IOException
- If an error occurs while disconnecting.public boolean isAllowedToPost()
public int sendCommand(String command, String args) throws IOException
getReplyString
.
command
- The text representation of the NNTP command to send.args
- The arguments to the NNTP command. If this parameter is
set to null, then the command is sent with no argument.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int sendCommand(int command, String args) throws IOException
getReplyString
.
command
- The NNTPCommand constant corresponding to the NNTP command
to send.args
- The arguments to the NNTP command. If this parameter is
set to null, then the command is sent with no argument.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int sendCommand(String command) throws IOException
getReplyString
.
command
- The text representation of the NNTP command to send.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int sendCommand(int command) throws IOException
getReplyString
.
command
- The NNTPCommand constant corresponding to the NNTP command
to send.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int getReplyCode()
connect
is of type void.
public int getReply() throws IOException
getReplyString
. Only use this
method if you are implementing your own NNTP client or if you need to
fetch a secondary response from the NNTP server.
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.
IOException
- If an I/O error occurs while
receiving the server reply.public String getReplyString()
public int article(String messageId) throws IOException
messageId
- The message identifier of the requested article,
including the encapsulating < and > characters.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int article(int articleNumber) throws IOException
articleNumber
- The number of the article to request from the
currently selected newsgroup.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int article() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int body(String messageId) throws IOException
messageId
- The message identifier of the requested article,
including the encapsulating < and > characters.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int body(int articleNumber) throws IOException
articleNumber
- The number of the article to request from the
currently selected newsgroup.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int body() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int head(String messageId) throws IOException
messageId
- The message identifier of the requested article,
including the encapsulating < and > characters.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int head(int articleNumber) throws IOException
articleNumber
- The number of the article to request from the
currently selected newsgroup.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int head() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int stat(String messageId) throws IOException
messageId
- The message identifier of the requested article,
including the encapsulating < and > characters.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int stat(int articleNumber) throws IOException
articleNumber
- The number of the article to request from the
currently selected newsgroup.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int stat() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int group(String newsgroup) throws IOException
newsgroup
- The name of the newsgroup to select.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int help() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int ihave(String messageId) throws IOException
messageId
- The article identifier,
including the encapsulating < and > characters.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int last() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int list() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int next() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int newgroups(String date, String time, boolean GMT, String distributions) throws IOException
date
- The date after which to check for new groups.
Date format is YYMMDDtime
- The time after which to check for new groups.
Time format is HHMMSS using a 24-hour clock.GMT
- True if the time is in GMT, false if local server time.distributions
- Comma-separated distribution list to check for
new groups. Set to null if no distributions.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int newnews(String newsgroups, String date, String time, boolean GMT, String distributions) throws IOException
newsgroups
- A comma-separated list of newsgroups to check for new
news.date
- The date after which to check for new news.
Date format is YYMMDDtime
- The time after which to check for new news.
Time format is HHMMSS using a 24-hour clock.GMT
- True if the time is in GMT, false if local server time.distributions
- Comma-separated distribution list to check for
new news. Set to null if no distributions.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int post() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int quit() throws 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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int authinfoUser(String username) throws IOException
username
- A valid username.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int authinfoPass(String password) throws IOException
password
- a valid password.
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int xover(String selectedArticles) throws IOException
selectedArticles
- a String representation of the range of
article headers required. This may be an article number, or a
range of article numbers in the form "XXXX-YYYY", where XXXX
and YYYY are valid article numbers in the current group. It
also may be of the form "XXX-", meaning "return XXX and all
following articles" In this revision, the last format is not
possible (yet).
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int xhdr(String header, String selectedArticles) throws IOException
header
- a String naming a header line (e.g., "subject"). See
RFC-1036 for a list of valid header lines.selectedArticles
- a String representation of the range of
article headers required. This may be an article number, or a
range of article numbers in the form "XXXX-YYYY", where XXXX
and YYYY are valid article numbers in the current group. It
also may be of the form "XXX-", meaning "return XXX and all
following articles" In this revision, the last format is not
possible (yet).
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.
IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public int listActive(String wildmat) throws IOException
wildmat
- A wildmat (pseudo-regex) pattern. See RFC 2980 for
details.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |