01: import java.net.*;
02: import java.io.*;
03:
04:
05:
06:
07:
08:
09: public class URLReader {
10: private URL my_adress;
11: private StringBuffer my_content;
12:
13:
14:
15:
16:
17:
18: public void read_new_url ( String web_address )
19: {
20: if( my_content != null ) {
21: my_content.delete( 0, my_content.length() );
22: }
23: my_content = new StringBuffer( );
24: try {
25: my_adress = new URL( web_address );
26: BufferedReader in = new BufferedReader(
27: new InputStreamReader(
28: my_adress.openStream( ) ) );
29:
30: String inputLine;
31:
32: while( (inputLine = in.readLine()) != null )
33: my_content.append( inputLine + "\n" );
34:
35: in.close();
36:
37: }
38: catch( UnknownHostException exception ) {
39:
40: System.err.println( "ERROR: ADDRESS IS NOT FOUND IN 'URLReader' CLASS!" );
41: System.err.println( "EXCEPTION DETAIL:\n" + exception.toString( ) + "\n");
42: }
43: catch( MalformedURLException exception ) {
44:
45: System.err.println( "ERROR: ADDRESS IS MALFORMED IN 'URLReader' CLASS!" );
46: System.err.println( "EXCEPTION DETAIL:\n" + exception.toString( ) + "\n");
47: }
48: catch (IOException exception ) {
49:
50: System.err.println( "ERROR: INPUT/OUTPUT EXCEPTION IN 'URLReader' CLASS!" );
51: System.err.println( "EXCEPTION DETAIL:\n" + exception.toString( ) + "\n");
52: }
53: }
54:
55:
56:
57:
58:
59:
60: public String get_content( )
61: {
62: return my_content.toString( );
63: }
64:
65:
66:
67:
68:
69: public String get_address( )
70: {
71: return my_adress.toString();
72: }
73:
74: }