Example usage for org.apache.commons.net.nntp NewGroupsOrNewsQuery getNewsgroups

List of usage examples for org.apache.commons.net.nntp NewGroupsOrNewsQuery getNewsgroups

Introduction

In this page you can find the example usage for org.apache.commons.net.nntp NewGroupsOrNewsQuery getNewsgroups.

Prototype

public String getNewsgroups() 

Source Link

Document

Return the comma separated list of newsgroups.

Usage

From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java

/**
 * List all new articles added to the NNTP server since a particular
 * date subject to the conditions of the specified query.  If no new
 * new news is found, no entries will be returned.
 * This uses the "NEWNEWS" command.// w  ww  . j  av  a2  s.c o  m
 * You must add at least one newsgroup to the query, else the command will fail.
 * Each String which is returned is a unique message identifier including the
 * enclosing &lt and &gt.
 * <p>
 * @param query  The query restricting how to search for new news.  You
 *    must add at least one newsgroup to the query.
 * @return An iterator of String instances containing the unique message
 *    identifiers for each new article added to the NNTP server.  If no
 *    new news is found, no strings 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.
 * @since 3.0
 */
@Override
public Iterable<String> iterateNewNews(NewGroupsOrNewsQuery query) throws IOException {
    if (NNTPReply.isPositiveCompletion(newnews(query.getNewsgroups(), query.getDate(), query.getTime(),
            query.isGMT(), query.getDistributions()))) {
        return new ReplyIterator(_reader_);
    }
    throw new IOException("NEWNEWS command failed: " + getReplyString());
}

From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java

/***
 * List all new articles added to the NNTP server since a particular
 * date subject to the conditions of the specified query.  If no new
 * new news is found, a zero length array will be returned.  If the
 * command fails, null will be returned.  You must add at least one
 * newsgroup to the query, else the command will fail.  Each String
 * in the returned array is a unique message identifier including the
 * enclosing &lt and &gt.//  w ww  .  j  av  a  2  s . c om
 * This uses the "NEWNEWS" command.
 * <p>
 * @param query  The query restricting how to search for new news.  You
 *    must add at least one newsgroup to the query.
 * @return An array of String instances containing the unique message
 *    identifiers for each new article added to the NNTP server.  If no
 *    new news is found, 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.
 *
 * @see #iterateNewNews(NewGroupsOrNewsQuery)
 ***/
@Override
public String[] listNewNews(NewGroupsOrNewsQuery query) throws IOException {
    if (!NNTPReply.isPositiveCompletion(newnews(query.getNewsgroups(), query.getDate(), query.getTime(),
            query.isGMT(), query.getDistributions()))) {
        return null;
    }

    Vector<String> list = new Vector<String>();
    BufferedReader reader = new DotTerminatedMessageReader(_reader_);

    String line;
    try {
        while ((line = reader.readLine()) != null) {
            list.addElement(line);
        }
    } finally {
        reader.close();
    }

    int size = list.size();
    if (size < 1) {
        return new String[0];
    }

    String[] result = new String[size];
    list.copyInto(result);

    return result;
}