List of usage examples for org.apache.commons.net.nntp NNTPClient iterateNewsgroups
public Iterable<NewsgroupInfo> iterateNewsgroups(String wildmat) throws IOException
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 www .j a v a 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;// w w w . j a v a 2 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); } } }