public class HTMLReader
extends java.io.Reader
HTMLReader r=new HTMLReader(new File("index.html"));
int c;
while((c=r.read())!=-1) {
if(c==-2) System.out.print(" TAG:",r.getTag());
else System.out.print(c);
}
-->
This is the HTML-file, with resolved ampersand sequences
and with -2 returned for tags.
If the file is UTF8-encoded, consider wrapping an UTF8Reader:
HTMLReader r=new HTMLReader(new UTF8Reader(new File("index.html")));
| Modifier and Type | Field and Description |
|---|---|
protected long |
announceChars
number of chars for announce (or -1)
|
protected java.io.Reader |
in
Holds the actual reader
|
boolean |
skipSTYLE
TRUE to skip STYLE attributes
|
protected java.lang.String |
tag
Holds the last tag (uppercased)
|
protected java.lang.String |
tagContent
Holds the content of the last tag
|
| Constructor and Description |
|---|
HTMLReader(java.io.File f)
Constructs a HTMLReader from a File
|
HTMLReader(java.io.File f,
java.lang.String message)
Constructs a HTMLReader from a File with a progress bar
|
HTMLReader(java.io.Reader s)
Constructs a HTMLReader from a Reader
|
HTMLReader(java.net.URL url)
Constructs a HTMLReader for an URL
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
java.lang.String |
getTag()
Returns the last tag (uppercased)
|
java.lang.String |
getTagContent()
Returns the content of the last tag
|
static void |
main(java.lang.String[] argv)
Test routine
|
int |
read()
Reads a character, returns -2 for tags
|
int |
read(char[] cbuf,
int off,
int len) |
java.lang.String |
readTaggedText(java.lang.String t)
Seeks the next tag of name t and returns all text
to the terminating tag /t.
|
java.lang.String |
readTextLine(int n)
Reads a sequence of characters
up to the blank following the nth char, ignores tags
|
boolean |
scrollTo(java.lang.String s)
Seeks a specific string and scrolls to it, returns TRUE if found
|
boolean |
scrollToTag(java.lang.String s)
Seeks a specific tag and scrolls to it, returns TRUE if found
|
java.lang.StringBuilder |
text(java.lang.String forTag)
Returns the entire text
|
protected java.io.Reader in
protected long announceChars
public boolean skipSTYLE
protected java.lang.String tagContent
protected java.lang.String tag
public HTMLReader(java.io.Reader s)
public HTMLReader(java.net.URL url)
throws java.io.IOException
java.io.IOExceptionpublic HTMLReader(java.io.File f)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic HTMLReader(java.io.File f,
java.lang.String message)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic java.lang.String readTextLine(int n)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getTagContent()
public java.lang.String getTag()
public int read()
throws java.io.IOException
read in class java.io.Readerjava.io.IOExceptionpublic java.lang.String readTaggedText(java.lang.String t)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.StringBuilder text(java.lang.String forTag)
throws java.io.IOException
java.io.IOExceptionpublic boolean scrollTo(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic boolean scrollToTag(java.lang.String s)
throws java.io.IOException
java.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Readerjava.io.IOExceptionpublic int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
read in class java.io.Readerjava.io.IOExceptionpublic static void main(java.lang.String[] argv)
throws java.lang.Exception
java.lang.Exception