FileDocCategorySizeDatePackage
NewsArticleDB.javaAPI DocExample1452Sat Dec 02 19:43:56 GMT 2000jabadot

NewsArticleDB

public class NewsArticleDB extends Object

Fields Summary
static final String
DIR
Constructors Summary
Methods Summary
public java.util.ArrayListgetCurrentArticles()


	     
		String[] files = new File(DIR).list();
		Arrays.sort(files);
		ArrayList al = new ArrayList();
		for (int i=0; i<files.length; i++) {
			NewsArticle art = new NewsArticle();
			art.setFileName(files[i]);
			BufferedReader is = new BufferedReader(new FileReader(
				DIR + files[i]));
			String line;
			while ((line = is.readLine()) != null)  {
				// Standard RFC822 null line after header
				if (line.length() == 0)
					break;
				// System.out.println(">>" + line);
				if (line.startsWith("Subject:"))
					art.setSubject(line.substring(line.indexOf(':")+1));
				else if (line.startsWith("Date:"))
					art.setDate(line.substring(line.indexOf(':")+1));
				else if (line.startsWith("From:"))
					art.setFrom(line.substring(line.indexOf(':")+1));
			}
			StringBuffer message = new StringBuffer();
			while ((line = is.readLine()) != null)  {
				message.append(line);
				message.append(' ");
			}
			art.setMessage(message.toString());
			al.add(art);
		}
		return al;
	
public static voidmain(java.lang.String[] args)

		ArrayList al = new NewsArticleDB().getCurrentArticles();
		for (int i=0; i<al.size(); i++) {
			System.out.println(al.get(i));
		}