Example usage for org.apache.commons.net.nntp NNTPClient iterateNewsgroupListing

List of usage examples for org.apache.commons.net.nntp NNTPClient iterateNewsgroupListing

Introduction

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

Prototype

public Iterable<String> iterateNewsgroupListing(String wildmat) throws IOException 

Source Link

Document

List the newsgroups that match a given pattern.

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;//w ww.j  a va  2s.co  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);
        }
    }

}

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  w  w . jav a 2 s .  c om
    }

    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);
        }
    }

}