/Users/lyon/j4p/src/net/server/servlets/Proxy.java

1    package net.server.servlets; 
2     
3    import java.io.BufferedReader; 
4    import java.io.IOException; 
5    import java.io.InputStreamReader; 
6    import java.io.PrintWriter; 
7    import java.net.URL; 
8    import java.util.Vector; 
9     
10   public class Proxy { 
11       public static void main(String args[]) { 
12           System.out.println("web browser started"); 
13           print( 
14                   getUrl("http://www.msn.com")); 
15       } 
16    
17       public static Vector getUrl(String 
18               _urlString) { 
19           try { 
20               URL url 
21                       = new URL(_urlString); 
22               System.out.println("url=" 
23                       + url); 
24               return 
25                       getUrl(url); 
26           } catch (Exception e) { 
27               e.printStackTrace(); 
28               return null; 
29           } 
30       } 
31    
32       public static Vector getUrl(URL url) 
33               throws IOException { 
34           Vector v = new Vector(); 
35           BufferedReader br 
36                   = new BufferedReader( 
37                           new InputStreamReader( 
38                                   url.openStream())); 
39           for (String l = br.readLine(); 
40                l != null; 
41                l = br.readLine()) 
42               v.addElement(l); 
43           return v; 
44       } 
45    
46       public static void print(Vector v) { 
47           System.out.println("Vector print"); 
48           for (int i = 0; i < v.size(); i++) 
49               System.out.println((String) v.elementAt(i)); 
50       } 
51    
52       public static void print(Vector v, PrintWriter pw) { 
53           pw.println("Vector print"); 
54           for (int i = 0; i < v.size(); i++) 
55               pw.println((String) v.elementAt(i)); 
56       } 
57   } 
58