import sun.net.nntp.*; import java.io.*; public class DumpHeaders { public static void main(String[] args) { String server = "news"; String newsgroup = ""; try { newsgroup = args[0]; } catch (ArrayIndexOutOfBoundsException e) { System.err.println("Usage: java DumpNews newsgroup server"); System.exit(1); } try { server = args[1]; } catch (ArrayIndexOutOfBoundsException e) { } try { NntpClient nc = new NntpClient(server); nc.setGroup(newsgroup); NewsgroupInfo ni = nc.getGroup(newsgroup); int first = ni.firstArticle; int last = ni.lastArticle; for (int i = first; i <= last; i++) { try { InputStream theHeader = nc.getHeader(i); BufferedReader br = new BufferedReader(new InputStreamReader(theHeader)); String theLine; System.out.println("-----------------\nHeader " + i); while ((theLine = br.readLine()) != null) { System.out.println(theLine); } } catch (NntpProtocolException ne) { // probably a cancelled article, just skip it } } } catch (IOException e) { System.err.println(e); } } }