Example usage for org.apache.commons.net.nntp NewsgroupInfo getFirstArticleLong

List of usage examples for org.apache.commons.net.nntp NewsgroupInfo getFirstArticleLong

Introduction

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

Prototype

public long getFirstArticleLong() 

Source Link

Document

Get the number of the first article in the newsgroup.

Usage

From source file:examples.nntp.MessageThreading.java

public static void main(String[] args) throws SocketException, IOException {

    if (args.length != 2 && args.length != 4) {
        System.out.println("Usage: MessageThreading <hostname> <groupname> [<user> <password>]");
        return;//from  w  w w  . j  a  v  a  2  s.  co  m
    }

    String hostname = args[0];
    String newsgroup = args[1];

    NNTPClient client = new NNTPClient();
    client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
    client.connect(hostname);

    if (args.length == 4) { // Optional auth
        String user = args[2];
        String password = args[3];
        if (!client.authenticate(user, password)) {
            System.out.println("Authentication failed for user " + user + "!");
            System.exit(1);
        }
    }

    String fmt[] = client.listOverviewFmt();
    if (fmt != null) {
        System.out.println("LIST OVERVIEW.FMT:");
        for (String s : fmt) {
            System.out.println(s);
        }
    } else {
        System.out.println("Failed to get OVERVIEW.FMT");
    }
    NewsgroupInfo group = new NewsgroupInfo();
    client.selectNewsgroup(newsgroup, group);

    long lowArticleNumber = group.getFirstArticleLong();
    long highArticleNumber = lowArticleNumber + 5000;

    System.out
            .println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]");
    Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);

    System.out.println("Building message thread tree...");
    Threader threader = new Threader();
    Article root = (Article) threader.thread(articles);

    Article.printThread(root, 0);
}

From source file:examples.nntp.ExtendedNNTPOps.java

private void demo(String host, String user, String password) {
    try {//from   ww w .j a  va  2 s  . c  om
        client.connect(host);

        // AUTHINFO USER/AUTHINFO PASS
        if (user != null && password != null) {
            boolean success = client.authenticate(user, password);
            if (success) {
                System.out.println("Authentication succeeded");
            } else {
                System.out.println("Authentication failed, error =" + client.getReplyString());
            }
        }

        // XOVER
        NewsgroupInfo testGroup = new NewsgroupInfo();
        client.selectNewsgroup("alt.test", testGroup);
        long lowArticleNumber = testGroup.getFirstArticleLong();
        long highArticleNumber = lowArticleNumber + 100;
        Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);

        for (Article article : articles) {
            if (article.isDummy()) { // Subject will contain raw response
                System.out.println("Could not parse: " + article.getSubject());
            } else {
                System.out.println(article.getSubject());
            }
        }

        // LIST ACTIVE
        NewsgroupInfo[] fanGroups = client.listNewsgroups("alt.fan.*");
        for (NewsgroupInfo fanGroup : fanGroups) {
            System.out.println(fanGroup.getNewsgroup());
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.common.net.examples.nntp.ExtendedNNTPOps.java

private void demo(String host, String user, String password) {
    try {//from   w  ww.  j  a  va2 s  .co m
        client.connect(host);

        // AUTHINFO USER/AUTHINFO PASS
        if (user != null && password != null) {
            boolean success = client.authenticate(user, password);
            if (success) {
                System.out.println("Authentication succeeded");
            } else {
                System.out.println("Authentication failed, error =" + client.getReplyString());
            }
        }

        // XOVER
        NewsgroupInfo testGroup = new NewsgroupInfo();
        client.selectNewsgroup("alt.test", testGroup);
        long lowArticleNumber = testGroup.getFirstArticleLong();
        long highArticleNumber = lowArticleNumber + 100;
        Iterable<Article> articles = client.iterateArticleInfo(lowArticleNumber, highArticleNumber);

        for (Article article : articles) {
            if (article.isDummy()) { // Subject will contain raw response
                System.out.println("Could not parse: " + article.getSubject());
            } else {
                System.out.println(article.getSubject());
            }
        }

        // LIST ACTIVE
        NewsgroupInfo[] fanGroups = client.listNewsgroups("alt.fan.*");
        for (int i = 0; i < fanGroups.length; ++i) {
            System.out.println(fanGroups[i].getNewsgroup());
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
}