FileDocCategorySizeDatePackage
ReadTag.javaAPI DocExample1952Fri May 05 11:05:22 BST 2000None

ReadTag

public class ReadTag extends Object
A simple but reusable HTML tag extractor.
author
Ian Darwin, Darwin Open Systems, www.darwinsys.com.
version
$Id: ReadTag.java,v 1.4 2000/05/05 14:05:23 ian Exp $

Fields Summary
protected URL
myURL
The URL that this ReadTag object is reading
protected BufferedReader
inrdr
The Reader for this object
Constructors Summary
public ReadTag(String theURLString)
Construct a ReadTag given a URL String


		this(new URL(theURLString));
	
public ReadTag(URL theURL)
Construct a ReadTag given a URL

		myURL = theURL;
		// Open the URL for reading
		inrdr = new BufferedReader(new InputStreamReader(myURL.openStream()));
	
Methods Summary
public voidclose()

		inrdr.close();
	
public static voidmain(java.lang.String[] args)

  
	/* Simple main showing one way of using the ReadTag class. */
	        
		if (args.length == 0) {
			System.err.println("Usage: ReadTag URL [...]");
			return;
		}

		for (int i=0; i<args.length; i++) {
			ReadTag rt = new ReadTag(args[0]);
			String tag;
			while ((tag = rt.nextTag()) != null) {
				System.out.println(tag);
			}
			rt.close();
		}
	
public java.lang.StringnextTag()
Read the next tag.

		int i;
		while ((i = inrdr.read()) != -1) {
			char thisChar = (char)i;
			if (thisChar == '<") {
				String tag = readTag();
				return tag;
			}
		}
		return null;
	
protected java.lang.StringreadTag()
Read one tag. Adapted from code by Elliotte Rusty Harold

		StringBuffer theTag = new StringBuffer("<");
		int i = '<";
	  
		while (i != '>" && (i = inrdr.read()) != -1) {
				theTag.append((char)i);
		}     
		return theTag.toString();
	
public java.lang.StringtoString()

		return "ReadTag[" + myURL.toString() + "]";