List of usage examples for org.apache.commons.net.nntp NewsgroupInfo getLastArticleLong
public long getLastArticleLong()
From source file:examples.nntp.ArticleReader.java
public static void main(String[] args) throws SocketException, IOException { if (args.length != 2 && args.length != 3 && args.length != 5) { System.out.println(/*from w w w . ja va2s. c om*/ "Usage: MessageThreading <hostname> <groupname> [<article specifier> [<user> <password>]]"); return; } String hostname = args[0]; String newsgroup = args[1]; // Article specifier can be numeric or Id in form <m.n.o.x@host> String articleSpec = args.length >= 3 ? args[2] : null; NNTPClient client = new NNTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); client.connect(hostname); if (args.length == 5) { // Optional auth String user = args[3]; String password = args[4]; if (!client.authenticate(user, password)) { System.out.println("Authentication failed for user " + user + "!"); System.exit(1); } } NewsgroupInfo group = new NewsgroupInfo(); client.selectNewsgroup(newsgroup, group); BufferedReader br; String line; if (articleSpec != null) { br = (BufferedReader) client.retrieveArticleHeader(articleSpec); } else { long articleNum = group.getLastArticleLong(); br = client.retrieveArticleHeader(articleNum); } if (br != null) { while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); } if (articleSpec != null) { br = (BufferedReader) client.retrieveArticleBody(articleSpec); } else { long articleNum = group.getLastArticleLong(); br = client.retrieveArticleBody(articleNum); } if (br != null) { while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); } }
From source file:org.apache.commons.net.examples.nntp.ArticleReader.java
public static void main(String[] args) throws SocketException, IOException { if (args.length != 2 && args.length != 3 && args.length != 5) { System.out.println(//from ww w .jav a 2 s .c o m "Usage: MessageThreading <hostname> <groupname> [<article specifier> [<user> <password>]]"); return; } String hostname = args[0]; String newsgroup = args[1]; // Article specifier can be numeric or Id in form <m.n.o.x@host> String articleSpec = args.length >= 3 ? args[2] : null; NNTPClient client = new NNTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); client.connect(hostname); if (args.length == 5) { // Optional auth String user = args[3]; String password = args[4]; if (!client.authenticate(user, password)) { System.out.println("Authentication failed for user " + user + "!"); System.exit(1); } } NewsgroupInfo group = new NewsgroupInfo(); client.selectNewsgroup(newsgroup, group); BufferedReader brHdr; String line; if (articleSpec != null) { brHdr = (BufferedReader) client.retrieveArticleHeader(articleSpec); } else { long articleNum = group.getLastArticleLong(); brHdr = client.retrieveArticleHeader(articleNum); } if (brHdr != null) { while ((line = brHdr.readLine()) != null) { System.out.println(line); } brHdr.close(); } BufferedReader brBody; if (articleSpec != null) { brBody = (BufferedReader) client.retrieveArticleBody(articleSpec); } else { long articleNum = group.getLastArticleLong(); brBody = client.retrieveArticleBody(articleNum); } if (brBody != null) { while ((line = brBody.readLine()) != null) { System.out.println(line); } brBody.close(); } }