Class NNTP
- Direct Known Subclasses:
NNTPClient
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.
- Author:
- Daniel F. Savarese
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ProtocolCommandSupport
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents.static final int
The default NNTP port.Fields inherited from class com.oroinc.net.SocketClient
_defaultPort_, _input_, _isConnected_, _output_, _socket_, _socketFactory_, _timeout_, NETASCII_EOL
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Initiates control connections and gets initial reply, determining if the client is allowed to post to the server.void
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
A convenience method to send the NNTP ARTICLE command to the server, receive the initial 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
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code.void
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
Returns the integer value of the reply code of the last NNTP reply.Returns the entire text of the last NNTP server response exactly as it was received, not including the end of line marker.int
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
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
A convenience method to send the NNTP IHAVE command to the server, receive the reply, and return the reply code.boolean
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
A convenience method to send the NNTP NEWGROUPS command to the server, receive the reply, and return the reply code.int
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
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
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code.Methods inherited from class com.oroinc.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
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORTThe default NNTP port. Its value is 119 according to RFC 977.- See Also:
-
_commandSupport_
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents.
-
-
Constructor Details
-
NNTP
public NNTP()The default NNTP constructor. Sets the default port toDEFAULT_PORT
and initializes internal data structures for saving NNTP reply information.
-
-
Method Details
-
_connectAction_
Initiates control connections and gets initial reply, determining if the client is allowed to post to the server.- Overrides:
_connectAction_
in classSocketClient
- Throws:
IOException
-
addProtocolCommandListener
Adds a ProtocolCommandListener. Delegates this task to _commandSupport_ .- Parameters:
listener
- The ProtocolCommandListener to add.
-
removeProtocolCommandistener
Removes a ProtocolCommandListener. Delegates this task to _commandSupport_ .- Parameters:
listener
- The ProtocolCommandListener to remove.
-
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. The reply text and code information from the last command is voided so that the memory it used may be reclaimed.- Overrides:
disconnect
in classSocketClient
- Throws:
IOException
- If an error occurs while disconnecting.
-
isAllowedToPost
public boolean isAllowedToPost()Indicates whether or not the client is allowed to post articles to the server it is currently connected to.- Returns:
- True if the client can post articles to the server, false otherwise.
-
sendCommand
Sends an NNTP command to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the actual reply text can be accessed by calling getReplyString .- Parameters:
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.- Returns:
- The integer value of the NNTP reply code returned by the server in response to the command.
- Throws:
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.
-
sendCommand
Sends an NNTP command to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the actual reply text can be accessed by calling getReplyString .- Parameters:
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.- Returns:
- The integer value of the NNTP reply code returned by the server in response to the command. in response to the command.
- Throws:
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.
-
sendCommand
Sends an NNTP command with no arguments to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the actual reply text can be accessed by calling getReplyString .- Parameters:
command
- The text representation of the NNTP command to send.- Returns:
- The integer value of the NNTP reply code returned by the server in response to the command. in response to the command.
- Throws:
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.
-
sendCommand
Sends an NNTP command with no arguments to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the actual reply text can be accessed by calling getReplyString .- Parameters:
command
- The NNTPCommand constant corresponding to the NNTP command to send.- Returns:
- The integer value of the NNTP reply code returned by the server in response to the command. in response to the command.
- Throws:
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.
-
getReplyCode
public int getReplyCode()Returns the integer value of the reply code of the last NNTP reply. You will usually only use this method after you connect to the NNTP server to check that the connection was successful sinceconnect
is of type void.- Returns:
- The integer value of the reply code of the last NNTP reply.
-
getReply
Fetches a reply from the NNTP server and returns the integer reply code. After calling this method, the actual reply text can be accessed from 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.- Returns:
- The integer value of the reply code of the fetched NNTP reply. in response to the command.
- Throws:
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.
-
getReplyString
Returns the entire text of the last NNTP server response exactly as it was received, not including the end of line marker.- Returns:
- The entire text from the last NNTP response as a String.
-
article
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code.- Parameters:
messageId
- The message identifier of the requested article, including the encapsulating invalid input: '<' and invalid input: '>' characters.- Returns:
- The reply code received from the server.
- Throws:
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.
-
article
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code.- Parameters:
articleNumber
- The number of the article to request from the currently selected newsgroup.- Returns:
- The reply code received from the server.
- Throws:
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.
-
article
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
body
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code.- Parameters:
messageId
- The message identifier of the requested article, including the encapsulating invalid input: '<' and invalid input: '>' characters.- Returns:
- The reply code received from the server.
- Throws:
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.
-
body
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code.- Parameters:
articleNumber
- The number of the article to request from the currently selected newsgroup.- Returns:
- The reply code received from the server.
- Throws:
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.
-
body
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
head
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code.- Parameters:
messageId
- The message identifier of the requested article, including the encapsulating invalid input: '<' and invalid input: '>' characters.- Returns:
- The reply code received from the server.
- Throws:
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.
-
head
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code.- Parameters:
articleNumber
- The number of the article to request from the currently selected newsgroup.- Returns:
- The reply code received from the server.
- Throws:
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.
-
head
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
stat
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code.- Parameters:
messageId
- The message identifier of the requested article, including the encapsulating invalid input: '<' and invalid input: '>' characters.- Returns:
- The reply code received from the server.
- Throws:
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.
-
stat
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code.- Parameters:
articleNumber
- The number of the article to request from the currently selected newsgroup.- Returns:
- The reply code received from the server.
- Throws:
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.
-
stat
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
group
A convenience method to send the NNTP GROUP command to the server, receive the reply, and return the reply code.- Parameters:
newsgroup
- The name of the newsgroup to select.- Returns:
- The reply code received from the server.
- Throws:
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.
-
help
A convenience method to send the NNTP HELP command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
ihave
A convenience method to send the NNTP IHAVE command to the server, receive the reply, and return the reply code.- Parameters:
messageId
- The article identifier, including the encapsulating invalid input: '<' and invalid input: '>' characters.- Returns:
- The reply code received from the server.
- Throws:
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.
-
last
A convenience method to send the NNTP LAST command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
list
A convenience method to send the NNTP LIST command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
next
A convenience method to send the NNTP NEXT command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
newgroups
public int newgroups(String date, String time, boolean GMT, String distributions) throws IOException A convenience method to send the NNTP NEWGROUPS command to the server, receive the reply, and return the reply code.- Parameters:
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.- Returns:
- The reply code received from the server.
- Throws:
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.
-
newnews
public int newnews(String newsgroups, String date, String time, boolean GMT, String distributions) throws IOException A convenience method to send the NNTP NEWGROUPS command to the server, receive the reply, and return the reply code.- Parameters:
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.- Returns:
- The reply code received from the server.
- Throws:
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.
-
post
A convenience method to send the NNTP POST command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-
quit
A convenience method to send the NNTP QUIT command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
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.
-