FileDocCategorySizeDatePackage
ReadHeaders.javaAPI DocExample1662Tue Mar 13 15:32:30 GMT 2001None

ReadHeaders

public class ReadHeaders extends Object
Read a file return mail headers one at a time.

Fields Summary
protected BufferedReader
is
String
inputLine
Constructors Summary
public ReadHeaders(BufferedReader f)
Construct

		is = f;
	
Methods Summary
public static voidmain(java.lang.String[] av)
Main program showing how to use it

        switch(av.length) {
            case 0: 
				ReadHeaders r = new ReadHeaders(
					new BufferedReader(
                        new InputStreamReader(System.in))); 
				printit(r);
				break;
            default:
				for (int i=0; i<av.length; i++)
                    try {
						ReadHeaders rr = new ReadHeaders(
							new BufferedReader(new FileReader(av[i])));
						printit(rr);
                    } catch (FileNotFoundException e) {
                        System.err.println(e);
                    }
				break;
        }
    
public booleanmore()
check to see if more headers available

		if (is == null)
			return false;
        try {

            inputLine = is.readLine();
			if (inputLine == null || inputLine.length() == 0) {
				is.close();
				is = null;
			}
        } catch (IOException e) {
            System.out.println("IOException: " + e);
			is = null;
			return false;
        }
		return true;
    
public Headernext()

		int pos = inputLine.indexOf(":");
		if (pos < 0)
			return new Header("??", inputLine);
		return new Header(
			inputLine.substring(0, pos),
			inputLine.substring(pos + 1));
	
public static voidprintit(ReadHeaders r)
Simple demo showing how to use it

		while (r.more())  {
			Header h = r.next();
			System.out.println(h.type + " = " + h.text);
		}