Get a list of headers from a newsgroup (this howto is deprecated)Tag(s): DEPRECATED
This snippet uses an undocumented Sun package [JDK1.1]
import sun.net.nntp.*;
import java.io.*;
public class NntpHeader {
public static void main(String[] args)
throws IOException {
/*
** pass your news server as parameter
** eg. java NttpPost news.server.com
*/
NntpClient c = new NntpClient(args[0]);
String newsgroup = "alt.test";
c.setGroup(newsgroup);
NewsgroupInfo ni = c.getGroup(newsgroup);
int first = ni.firstArticle;
int last = ni.lastArticle;
for (int i = first; i <= last; i++) {
try {
InputStream theHeader = c.getHeader(i);
BufferedReader br = new BufferedReader(new
InputStreamReader(theHeader));
String theLine;
System.out.println("-----------------\nHeader " + i + "/" + last);
while ((theLine = br.readLine()) != null)
System.out.println(theLine);
}
catch (NntpProtocolException ne) {
/*
** probably a cancelled article, just skip it
*/
}
}
}
}
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com