public class HTMLReader extends 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 Reader |
in
Holds the actual reader
|
boolean |
skipSTYLE
TRUE to skip STYLE attributes
|
protected String |
tag
Holds the last tag (uppercased)
|
protected String |
tagContent
Holds the content of the last tag
|
| Constructor and Description |
|---|
HTMLReader(File f)
Constructs a HTMLReader from a File
|
HTMLReader(File f,
String message)
Constructs a HTMLReader from a File with a progress bar
|
HTMLReader(Reader s)
Constructs a HTMLReader from a Reader
|
HTMLReader(URL url)
Constructs a HTMLReader for an URL
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
String |
getTag()
Returns the last tag (uppercased)
|
String |
getTagContent()
Returns the content of the last tag
|
static void |
main(String[] argv)
Test routine
|
int |
read()
Reads a character, returns -2 for tags
|
int |
read(char[] cbuf,
int off,
int len) |
String |
readTaggedText(String t)
Seeks the next tag of name t and returns all text
to the terminating tag /t.
|
String |
readTextLine(int n)
Reads a sequence of characters
up to the blank following the nth char, ignores tags
|
boolean |
scrollTo(String s)
Seeks a specific string and scrolls to it, returns TRUE if found
|
boolean |
scrollToTag(String s)
Seeks a specific tag and scrolls to it, returns TRUE if found
|
StringBuilder |
text(String forTag)
Returns the entire text
|
protected Reader in
protected long announceChars
public boolean skipSTYLE
protected String tagContent
protected String tag
public HTMLReader(Reader s)
public HTMLReader(URL url) throws IOException
IOExceptionpublic HTMLReader(File f) throws FileNotFoundException
FileNotFoundExceptionpublic HTMLReader(File f, String message) throws FileNotFoundException
FileNotFoundExceptionpublic String readTextLine(int n) throws IOException
IOExceptionpublic String getTagContent()
public String getTag()
public int read()
throws IOException
read in class ReaderIOExceptionpublic String readTaggedText(String t) throws IOException
IOExceptionpublic StringBuilder text(String forTag) throws IOException
IOExceptionpublic boolean scrollTo(String s) throws IOException
IOExceptionpublic boolean scrollToTag(String s) throws IOException
IOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class ReaderIOExceptionpublic int read(char[] cbuf,
int off,
int len)
throws IOException
read in class ReaderIOExceptionCopyright © 2018. All rights reserved.