nntpclient.java

来自「apache推出的net包」· Java 代码 · 共 1,285 行 · 第 1/4 页

JAVA
1,285
字号
    }    /***     * Select the specified newsgroup to be the target of for future article     * retrieval and posting operations.  Also return the newsgroup     * information contained in the server reply through the info parameter.     * <p>     * @param newsgroup  The newsgroup to select.     * @param 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.     * @return True if the newsgroup exists and was selected, false otherwise.     * @exception 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.     * @exception 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(String newsgroup, NewsgroupInfo info)    throws IOException    {        if (!NNTPReply.isPositiveCompletion(group(newsgroup)))            return false;        if (info != null)            __parseGroupReply(getReplyString(), info);        return true;    }    /*** Same as <code> selectNewsgroup(newsgroup, null) </code> ***/    public boolean selectNewsgroup(String newsgroup) throws IOException    {        return selectNewsgroup(newsgroup, null);    }    /***     * List the command help from the server.     * <p>     * @return The sever help information.     * @exception 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.     * @exception IOException  If an I/O error occurs while either sending a     *      command to the server or receiving a reply from the server.     ***/    public String listHelp() throws IOException    {        StringWriter help;        Reader reader;        if (!NNTPReply.isInformational(help()))            return null;        help = new StringWriter();        reader = new DotTerminatedMessageReader(_reader_);        Util.copyReader(reader, help);        reader.close();        help.close();        return help.toString();    }    /***     * Select an article by its unique identifier (including enclosing     * &lt and &gt) and return its article number and id through the     * pointer parameter.  This is achieved through the STAT command.     * According to RFC 977, this will NOT set the current article pointer     * on the server.  To do that, you must reference the article by its     * number.     * <p>     * @param articleId  The unique article identifier of the article that     *    is being selectedd.  If this parameter is null, the     *    body of the current article is selected     * @param 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.     * @return True if successful, false if not.     * @exception 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.     * @exception 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(String articleId, ArticlePointer pointer)    throws IOException    {        if (articleId != null)        {            if (!NNTPReply.isPositiveCompletion(stat(articleId)))                return false;        }        else        {            if (!NNTPReply.isPositiveCompletion(stat()))                return false;        }        if (pointer != null)            __parseArticlePointer(getReplyString(), pointer);        return true;    }    /**** Same as <code> selectArticle(articleId, null) </code> ***/    public boolean selectArticle(String articleId) throws IOException    {        return selectArticle(articleId, null);    }    /****     * Same as <code> selectArticle(null, articleId) </code>.  Useful     * for retrieving the current article number.     ***/    public boolean selectArticle(ArticlePointer pointer) throws IOException    {        return selectArticle(null, pointer);    }    /***     * Select an article in the currently selected newsgroup by its number.     * and return its article number and id through the     * pointer parameter.  This is achieved through the STAT command.     * According to RFC 977, this WILL set the current article pointer     * on the server.  Use this command to select an article before retrieving     * it, or to obtain an article's unique identifier given its number.     * <p>     * @param articleNumber The number of the article to select from the     *       currently selected newsgroup.     * @param 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.     * @return True if successful, false if not.     * @exception 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.     * @exception 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(int articleNumber, ArticlePointer pointer)    throws IOException    {        if (!NNTPReply.isPositiveCompletion(stat(articleNumber)))            return false;        if (pointer != null)            __parseArticlePointer(getReplyString(), pointer);        return true;    }    /*** Same as <code> selectArticle(articleNumber, null) </code> ***/    public boolean selectArticle(int articleNumber) throws IOException    {        return selectArticle(articleNumber, null);    }    /***     * Select the article preceeding the currently selected article in the     * currently selected newsgroup and return its number and unique id     * through the pointer parameter.  Because of deviating server     * implementations, the articleId information cannot be trusted.  To     * obtain the article identifier, issue a     * <code> selectArticle(pointer.articleNumber, pointer) </code> immediately     * afterward.     * <p>     * @param 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.     * @return True if successful, false if not (e.g., there is no previous     *     article).     * @exception 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.     * @exception 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(ArticlePointer pointer)    throws IOException    {        if (!NNTPReply.isPositiveCompletion(last()))            return false;        if (pointer != null)            __parseArticlePointer(getReplyString(), pointer);        return true;    }    /*** Same as <code> selectPreviousArticle(null) </code> ***/    public boolean selectPreviousArticle() throws IOException    {        return selectPreviousArticle(null);    }    /***     * Select the article following the currently selected article in the     * currently selected newsgroup and return its number and unique id     * through the pointer parameter.  Because of deviating server     * implementations, the articleId information cannot be trusted.  To     * obtain the article identifier, issue a     * <code> selectArticle(pointer.articleNumber, pointer) </code> immediately     * afterward.     * <p>     * @param 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.     * @return True if successful, false if not (e.g., there is no following     *         article).     * @exception 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.     * @exception 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(ArticlePointer pointer) throws IOException    {        if (!NNTPReply.isPositiveCompletion(next()))            return false;        if (pointer != null)            __parseArticlePointer(getReplyString(), pointer);        return true;    }    /*** Same as <code> selectNextArticle(null) </code> ***/    public boolean selectNextArticle() throws IOException    {        return selectNextArticle(null);    }    /***     * List all newsgroups served by the NNTP server.  If no newsgroups     * are served, a zero length array will be returned.  If the command     * fails, null will be returned.     * <p>     * @return An array of NewsgroupInfo instances containing the information     *    for each newsgroup served by the NNTP server.   If no newsgroups     *    are served, a zero length array will be returned.  If the command     *    fails, null will be returned.     * @exception 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.     * @exception 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() throws IOException    {        if (!NNTPReply.isPositiveCompletion(list()))            return null;        return __readNewsgroupListing();    }    /**     * An overloaded listNewsgroups() command that allows us to     * specify with a pattern what groups we want to list. Wraps the     * LIST ACTIVE command.     * <p>     * @param wildmat a pseudo-regex pattern (cf. RFC 2980)     * @return An array of NewsgroupInfo instances containing the information     *    for each newsgroup served by the NNTP server corresponding to the     *    supplied pattern.   If no such newsgroups are served, a zero length     *    array will be returned.  If the command fails, null will be returned.     * @throws IOException     */    public NewsgroupInfo[] listNewsgroups(String wildmat) throws IOException    {        if(!NNTPReply.isPositiveCompletion(listActive(wildmat)))            return null;        return __readNewsgroupListing();    }    /***     * List all new newsgroups added to the NNTP server since a particular     * date subject to the conditions of the specified query.  If no new     * newsgroups were added, a zero length array will be returned.  If the     * command fails, null will be returned.     * <p>     * @param query  The query restricting how to search for new newsgroups.     * @return An array of NewsgroupInfo instances containing the information     *    for each new newsgroup added to the NNTP server.   If no newsgroups     *    were added, a zero length array will be returned.  If the command     *    fails, null will be returned.     * @exception 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.     * @exception IOException  If an I/O error occurs while either sending a

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?