We want to make a kind of WebReader that just lets us see the HTML tags.
We want to make a kind of WebReader that just lets us see the HTML tags.
We want to make a kind of WebReader that just lets us see the HTML tags.
We'll have to put in an explicit constructor, to match the constructor of the WebReader
We'll have to put in an explicit constructor, to match the constructor of the WebReader
We'll have to put in an explicit constructor, to match the constructor of the WebReader
The constructor just needs to call the WebReader constructor.
The constructor just needs to call the WebReader constructor.
The constructor just needs to call the WebReader constructor.
Only snag is that constructing a WebReader may throw an exception.
Only snag is that constructing a WebReader may throw an exception.
Only snag is that constructing a WebReader may throw an exception.
If we try and read a line from this class, then we will just get the next line from the original web page. We have to override the readLine() method to make it ignore all the text between the tags, so that each 'line' will correspond to a single tag in the WebReader.
If we try and read a line from this class, then we will just get the next line from the original web page. We have to override the readLine() method to make it ignore all the text between the tags, so that each 'line' will correspond to a single tag in the WebReader.
If we try and read a line from this class, then we will just get the next line from the original web page. We have to override the readLine() method to make it ignore all the text between the tags, so that each 'line' will correspond to a single tag in the WebReader.
To do this we need to read characters and return a line, so let's declare some variables.
To do this we need to read characters and return a line, so let's declare some variables.
To do this we need to read characters and return a line, so let's declare some variables.
Why was the 'ch' variable of type int? That's because read returns a deliberately wide type so that it can encode EOF conditions without clashing with any valid value.
To return a tag, we are going to need to skip any text preceding a '<' character, then collect all the text up to the next > character.
To return a tag, we are going to need to skip any text preceding a '<' character, then collect all the text up to the next > character.
To return a tag, we are going to need to skip any text preceding a '<' character, then collect all the text up to the next > character.
Hang on, how would we recognise when there are no more tags, i.e. when we hit the end of the file?
Hang on, how would we recognise when there are no more tags, i.e. when we hit the end of the file?
Hang on, how would we recognise when there are no more tags, i.e. when we hit the end of the file?
Now let's collect the tag data
Now let's collect the tag data
Now let's collect the tag data
... by appending it to the result ...
... by appending it to the result ...
... by appending it to the result ...
... oops, by appending it as a character ...
... oops, by appending it as a character ...
... oops, by appending it as a character ...
and when we've finished, just return the line (as a String).
and when we've finished, just return the line (as a String).
and when we've finished, just return the line (as a String).
Except of course in the case where there are no more tags left, in which case we'll return a null object
Except of course in the case where there are no more tags left, in which case we'll return a null object
Except of course in the case where there are no more tags left, in which case we'll return a null object
One more thing to deal with: we said that we wanted to return each tag as a separate line. But what happens if there is a line feed or carriage return in the middle of the tag? We'll have to replace that by a space.
One more thing to deal with: we said that we wanted to return each tag as a separate line. But what happens if there is a line feed or carriage return in the middle of the tag? We'll have to replace that by a space.
One more thing to deal with: we said that we wanted to return each tag as a separate line. But what happens if there is a line feed or carriage return in the middle of the tag? We'll have to replace that by a space.
And lastly, what happens if there is a network problem? We'll get some kind of exception thrown, so we must catch it and pretend we hit the end of the data...
And lastly, what happens if there is a network problem? We'll get some kind of exception thrown, so we must catch it and pretend we hit the end of the data...
And lastly, what happens if there is a network problem? We'll get some kind of exception thrown, so we must catch it and pretend we hit the end of the data...
And lastly, what happens if there is a network problem? We'll get some kind of exception thrown, so we must catch it and pretend we hit the end of the data...
And lastly, what happens if there is a network problem? We'll get some kind of exception thrown, so we must catch it and pretend we hit the end of the data...
Finished code.
class TagReader {
}
class TagReader {
}
class TagReader extends WebReader {
}
class TagReader extends WebReader {
}
class TagReader extends WebReader {
* }
class TagReader extends WebReader {
public TagReader(String url){
...
}
}
class TagReader extends WebReader {
public TagReader(String url){
...
}
}
class TagReader extends WebReader {
public TagReader(String url){
...
}
}
class TagReader extends WebReader {
public TagReader(String url){
super(url);
}
}
class TagReader extends WebReader {
public TagReader(String url){
super(url);
}
}
class TagReader extends WebReader {
public TagReader(String url){
super(url);
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
* }
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<')
ch=this.read();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<')
ch=this.read();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<')
ch=this.read();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
???
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
???
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
???
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append(ch);
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append(ch);
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append(ch);
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append((char)ch);
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append((char)ch);
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append((char)ch);
ch=this.read();
}
...
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append((char)ch);
ch=this.read();
}
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append((char)ch);
ch=this.read();
}
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append((char)ch);
ch=this.read();
}
*return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append((char)ch);
ch=this.read();
}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
line.append((char)ch);
ch=this.read();
}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
*line.append((char)ch);
ch=this.read();
}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
if(Character.isWhitespace((char)ch))line.append(' ');
else line.append((char)ch);
ch=this.read();
}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
if(Character.isWhitespace((char)ch))line.append(' ');
else line.append((char)ch);
ch=this.read();
}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
*while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
if(Character.isWhitespace((char)ch))line.append(' ');
else line.append((char)ch);
ch=this.read();
}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
try{
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
if(Character.isWhitespace((char)ch))line.append(' ');
else line.append((char)ch);
ch=this.read();
}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
try{
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
if(Character.isWhitespace((char)ch))line.append(' ');
else line.append((char)ch);
ch=this.read();
}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
try{
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
if(Character.isWhitespace((char)ch))line.append(' ');
else line.append((char)ch);
ch=this.read();
}
}
catch(IOException e){return null;}
if(ch==-1)return null;
return line.toString();
}
}
class TagReader extends WebReader {
public TagReader(String url) throws IOException {
super(url);
}
public String readLine(){
int ch;
StringBuffer result=new StringBuffer();
ch=this.read();
try{
while(ch!='<' && ch!=-1)
ch=this.read();
ch=this.read();
while(ch!='>' && ch!=-1){
if(Character.isWhitespace((char)ch))line.append(' ');
else line.append((char)ch);
ch=this.read();
}
}
catch(IOException e){return null;}
if(ch==-1)return null;
return line.toString();
}
}