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

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

Introduction

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

Prototype

public String getNewsgroup() 

Source Link

Document

Get the newsgroup name.

Usage

From source file:examples.nntp.ListNewsgroups.java

public static void main(String[] args) {
    if (args.length < 1) {
        System.err.println("Usage: newsgroups newsserver [pattern]");
        return;//from  w w w.ja va  2  s  .  com
    }

    NNTPClient client = new NNTPClient();
    String pattern = args.length >= 2 ? args[1] : "";

    try {
        client.connect(args[0]);

        int j = 0;
        try {
            for (String s : client.iterateNewsgroupListing(pattern)) {
                j++;
                System.out.println(s);
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        System.out.println(j);

        j = 0;
        for (NewsgroupInfo n : client.iterateNewsgroups(pattern)) {
            j++;
            System.out.println(n.getNewsgroup());
        }
        System.out.println(j);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (client.isConnected()) {
                client.disconnect();
            }
        } catch (IOException e) {
            System.err.println("Error disconnecting from server.");
            e.printStackTrace();
            System.exit(1);
        }
    }

}

From source file:examples.nntp.ExtendedNNTPOps.java

private void demo(String host, String user, String password) {
    try {/*w ww .  j  a v  a  2 s.  c  o 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 (NewsgroupInfo fanGroup : fanGroups) {
            System.out.println(fanGroup.getNewsgroup());
        }

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

From source file:me.lehrner.newsgroupsndy.presenter.tasks.UpdateGroupListAsyncTask.java

@Override
protected Boolean doInBackground(Server... servers) {
    mServerId = servers[0].getId();/*from w  w w . jav a  2 s  .  c  o  m*/

    String hostName = servers[0].getServerUrl();
    int lastVisitInt = servers[0].getLastVisit();

    NewsgroupInfo[] newsgroupInfos;
    ArrayList<String> groupNames = new ArrayList<>();

    try {
        NNTPClient nntpClient = new NNTPClient();
        nntpClient.connect(hostName, 119);

        Log.d(LOG_TAG, "lastVisitInt: " + lastVisitInt);

        if (lastVisitInt != 0) {
            Calendar lastVisit = Calendar.getInstance();
            lastVisit.setTimeInMillis(lastVisitInt * 1000L);

            NewGroupsOrNewsQuery query = new NewGroupsOrNewsQuery(lastVisit, false);
            newsgroupInfos = nntpClient.listNewNewsgroups(query);

            Log.d(LOG_TAG, "listNewNewsgroups");

        } else {
            newsgroupInfos = nntpClient.listNewsgroups();

            Log.d(LOG_TAG, "listNewsgroups");

        }

        nntpClient.disconnect();
    } catch (IOException e) {
        Log.d(LOG_TAG, "IOException");

        GroupPresenter groupPresenter = mGroupPresenterWeakReference.get();

        if (groupPresenter != null) {
            groupPresenter.updateNotSuccessful();
        }
        return false;
    }

    if (newsgroupInfos == null) {
        Log.d(LOG_TAG, "newsgroupInfos is null");
        return false;
    }

    for (NewsgroupInfo newsgroupInfo : newsgroupInfos) {
        groupNames.add(newsgroupInfo.getNewsgroup());
    }

    return mGroupRepository.saveGroups(mServerId, groupNames);
}

From source file:io.dimitris.newsgroupwatcher.NewsgroupWatcher.java

protected void watch() throws IOException {

    while (watching) {
        try {/*from  w  w  w.j ava2  s .c om*/
            //System.err.println("Watching ");
            client = new NNTPClient();
            client.connect(server);
            if (isAuthenticationRequired()) {
                client.authenticate(username, password);
            }

            client.selectNewsgroup(newsgroup);

            NewsgroupInfo newsgroupInfo = null;

            for (NewsgroupInfo ni : client.listNewsgroups()) {

                if (ni.getNewsgroup().equals(newsgroup)) {
                    newsgroupInfo = ni;
                    break;
                }
            }

            int newArticleCount = newsgroupInfo.getArticleCount();

            //if (articleCount == -1) {
            //   articleCount = newArticleCount;
            //}
            //else 
            if (articleCount < newArticleCount) {
                Reader articleReader = client.retrieveArticleHeader(newArticleCount);
                notifyNewArticleListeners(new ArticleHeader(articleReader));
                articleCount = newArticleCount;
            } else {
                //System.err.println("Still " + newArticleCount);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            sleep();
        }
    }
}

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

public final static void main(String[] args) {
    if (args.length < 1) {
        System.err.println("Usage: newsgroups newsserver [pattern]");
        return;/*from  w ww  . j  a  va2 s.  c  o  m*/
    }

    NNTPClient client = new NNTPClient();
    String pattern = args.length >= 2 ? args[1] : "";

    try {
        client.connect(args[0]);

        int j = 0;
        try {
            for (String s : client.iterateNewsgroupListing(pattern)) {
                j++;
                System.out.println(s);
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        System.out.println(j);

        j = 0;
        for (NewsgroupInfo n : client.iterateNewsgroups(pattern)) {
            j++;
            System.out.println(n.getNewsgroup());
        }
        System.out.println(j);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (client.isConnected()) {
                client.disconnect();
            }
        } catch (IOException e) {
            System.err.println("Error disconnecting from server.");
            e.printStackTrace();
            System.exit(1);
        }
    }

}