Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.commons.net.nntp
Class NNTP  view NNTP download NNTP.java

java.lang.Object
  extended byorg.apache.commons.net.SocketClient
      extended byorg.apache.commons.net.nntp.NNTP
Direct Known Subclasses:
NNTPClient

public class NNTP
extends org.apache.commons.net.SocketClient

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 55 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() 55 to properly clean up the system resources used by NNTP. Before disconnecting, you may check the last reply code and text with getReplyCode 55 and getReplyString 55 .

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 org.apache.commons.net.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.


Field Summary
private  java.lang.StringBuffer __commandBuffer
           
private static java.lang.String __DEFAULT_ENCODING
           
protected  org.apache.commons.net.ProtocolCommandSupport _commandSupport_
          A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents.
(package private)  boolean _isAllowedToPost
           
protected  java.io.BufferedReader _reader_
          Wraps SocketClient._input_>SocketClient._input_ 55 to communicate with server.
(package private)  int _replyCode
           
(package private)  java.lang.String _replyString
           
protected  java.io.BufferedWriter _writer_
          Wraps SocketClient._output_>SocketClient._output_ 55 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
private  void __getReply()
           
protected  void _connectAction_()
          Initiates control connections and gets initial reply, determining if the client is allowed to post to the server.
 void addProtocolCommandListener(org.apache.commons.net.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(java.lang.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(java.lang.String password)
          A convenience method to send the AUTHINFO PASS command to the server, receive the reply, and return the reply code.
 int authinfoUser(java.lang.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(java.lang.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.
 java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.String wildmat)
          A convenience wrapper for the extended LIST command that takes an argument, allowing us to selectively list multiple groups.
 int newgroups(java.lang.String date, java.lang.String time, boolean GMT, java.lang.String distributions)
          A convenience method to send the NNTP NEWGROUPS command to the server, receive the reply, and return the reply code.
 int newnews(java.lang.String newsgroups, java.lang.String date, java.lang.String time, boolean GMT, java.lang.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(org.apache.commons.net.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, java.lang.String args)
          Sends an NNTP command to the server, waits for a reply and returns the numerical response code.
 int sendCommand(java.lang.String command)
          Sends an NNTP command with no arguments to the server, waits for a reply and returns the numerical response code.
 int sendCommand(java.lang.String command, java.lang.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(java.lang.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(java.lang.String header, java.lang.String selectedArticles)
          A convenience method to send the NNTP XHDR command to the server, receive the reply, and return the reply code.
 int xover(java.lang.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

DEFAULT_PORT

public static final int DEFAULT_PORT
The default NNTP port. Its value is 119 according to RFC 977.

See Also:
Constant Field Values

__DEFAULT_ENCODING

private static final java.lang.String __DEFAULT_ENCODING
See Also:
Constant Field Values

__commandBuffer

private java.lang.StringBuffer __commandBuffer

_isAllowedToPost

boolean _isAllowedToPost

_replyCode

int _replyCode

_replyString

java.lang.String _replyString

_reader_

protected java.io.BufferedReader _reader_
Wraps SocketClient._input_>SocketClient._input_ 55 to communicate with server. Initialized by _connectAction_() 55 . All server reads should be done through this variable.


_writer_

protected java.io.BufferedWriter _writer_
Wraps SocketClient._output_>SocketClient._output_ 55 to communicate with server. Initialized by _connectAction_() 55 . All server reads should be done through this variable.


_commandSupport_

protected org.apache.commons.net.ProtocolCommandSupport _commandSupport_
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents.

Constructor Detail

NNTP

public NNTP()
The default NNTP constructor. Sets the default port to DEFAULT_PORT and initializes internal data structures for saving NNTP reply information.

Method Detail

__getReply

private void __getReply()
                 throws java.io.IOException

_connectAction_

protected void _connectAction_()
                        throws java.io.IOException
Initiates control connections and gets initial reply, determining if the client is allowed to post to the server. Initializes _reader_ 55 and _writer_ 55 to wrap SocketClient._input_>SocketClient._input_ 55 and SocketClient._output_>SocketClient._output_ 55 .


addProtocolCommandListener

public void addProtocolCommandListener(org.apache.commons.net.ProtocolCommandListener listener)
Adds a ProtocolCommandListener. Delegates this task to _commandSupport_ 55 .


removeProtocolCommandListener

public void removeProtocolCommandListener(org.apache.commons.net.ProtocolCommandListener listener)
Removes a ProtocolCommandListener. Delegates this task to _commandSupport_ 55 .


disconnect

public void disconnect()
                throws java.io.IOException
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.


isAllowedToPost

public boolean isAllowedToPost()
Indicates whether or not the client is allowed to post articles to the server it is currently connected to.


sendCommand

public int sendCommand(java.lang.String command,
                       java.lang.String args)
                throws java.io.IOException
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 55 .


sendCommand

public int sendCommand(int command,
                       java.lang.String args)
                throws java.io.IOException
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 55 .


sendCommand

public int sendCommand(java.lang.String command)
                throws java.io.IOException
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 55 .


sendCommand

public int sendCommand(int command)
                throws java.io.IOException
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 55 .


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 since connect is of type void.


getReply

public int getReply()
             throws java.io.IOException
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 55 . 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.


getReplyString

public java.lang.String getReplyString()
Returns the entire text of the last NNTP server response exactly as it was received, not including the end of line marker.


article

public int article(java.lang.String messageId)
            throws java.io.IOException
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code.


article

public int article(int articleNumber)
            throws java.io.IOException
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code.


article

public int article()
            throws java.io.IOException
A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code.


body

public int body(java.lang.String messageId)
         throws java.io.IOException
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code.


body

public int body(int articleNumber)
         throws java.io.IOException
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code.


body

public int body()
         throws java.io.IOException
A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code.


head

public int head(java.lang.String messageId)
         throws java.io.IOException
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code.


head

public int head(int articleNumber)
         throws java.io.IOException
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code.


head

public int head()
         throws java.io.IOException
A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code.


stat

public int stat(java.lang.String messageId)
         throws java.io.IOException
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code.


stat

public int stat(int articleNumber)
         throws java.io.IOException
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code.


stat

public int stat()
         throws java.io.IOException
A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code.


group

public int group(java.lang.String newsgroup)
          throws java.io.IOException
A convenience method to send the NNTP GROUP command to the server, receive the reply, and return the reply code.


help

public int help()
         throws java.io.IOException
A convenience method to send the NNTP HELP command to the server, receive the reply, and return the reply code.


ihave

public int ihave(java.lang.String messageId)
          throws java.io.IOException
A convenience method to send the NNTP IHAVE command to the server, receive the reply, and return the reply code.


last

public int last()
         throws java.io.IOException
A convenience method to send the NNTP LAST command to the server, receive the reply, and return the reply code.


list

public int list()
         throws java.io.IOException
A convenience method to send the NNTP LIST command to the server, receive the reply, and return the reply code.


next

public int next()
         throws java.io.IOException
A convenience method to send the NNTP NEXT command to the server, receive the reply, and return the reply code.


newgroups

public int newgroups(java.lang.String date,
                     java.lang.String time,
                     boolean GMT,
                     java.lang.String distributions)
              throws java.io.IOException
A convenience method to send the NNTP NEWGROUPS command to the server, receive the reply, and return the reply code.


newnews

public int newnews(java.lang.String newsgroups,
                   java.lang.String date,
                   java.lang.String time,
                   boolean GMT,
                   java.lang.String distributions)
            throws java.io.IOException
A convenience method to send the NNTP NEWGROUPS command to the server, receive the reply, and return the reply code.


post

public int post()
         throws java.io.IOException
A convenience method to send the NNTP POST command to the server, receive the reply, and return the reply code.


quit

public int quit()
         throws java.io.IOException
A convenience method to send the NNTP QUIT command to the server, receive the reply, and return the reply code.


authinfoUser

public int authinfoUser(java.lang.String username)
                 throws java.io.IOException
A convenience method to send the AUTHINFO USER command to the server, receive the reply, and return the reply code. (See RFC 2980)


authinfoPass

public int authinfoPass(java.lang.String password)
                 throws java.io.IOException
A convenience method to send the AUTHINFO PASS command to the server, receive the reply, and return the reply code. If this step is required, it should immediately follow the AUTHINFO USER command (See RFC 2980)


xover

public int xover(java.lang.String selectedArticles)
          throws java.io.IOException
A convenience method to send the NNTP XOVER command to the server, receive the reply, and return the reply code.


xhdr

public int xhdr(java.lang.String header,
                java.lang.String selectedArticles)
         throws java.io.IOException
A convenience method to send the NNTP XHDR command to the server, receive the reply, and return the reply code.


listActive

public int listActive(java.lang.String wildmat)
               throws java.io.IOException
A convenience wrapper for the extended LIST command that takes an argument, allowing us to selectively list multiple groups.