import java.net.URL;
import java.net.MalformedURLException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class FetchURL {

  java.util.Vector msgs = new java.util.Vector();

  String[] run(String address) {
    String[] messages;

    try {
      URL url = new URL(address);
      try {
	Object obj = url.getContent();

	if(obj instanceof String) {
	  System.out.println("obj is " + obj);
	  setText(obj.toString());
	} else {
	  System.out.println("obj is " + obj);
	  setText((InputStream)obj);
	}
      } catch(IOException ioe) {
      } catch(NullPointerException npe) {
      }
    } catch(MalformedURLException murle) {
    }

    messages = new String[msgs.size()];
    for(int i = 0; i < msgs.size(); i++) {
      messages[i] = " " + (String)msgs.elementAt(i);
    }

    return messages;
  }

  void setText(InputStream is) {
    String nextline;

    try {
      BufferedReader dis
	= new BufferedReader(new InputStreamReader(is));
      while((nextline = dis.readLine()) != null) {
	msgs.addElement(nextline);
      }
    } catch(IOException ioe) {
      msgs.addElement(ioe.toString());
    }
  }
  void setText(String content) {
    msgs.addElement(content);
  }

  void printResult(String[] messages) {
    for(int i = 0; i < messages.length; i++) {
      System.out.println(messages[i]);
    }
  }

  public static void main(String[] args) {
    String hostname;

    try {
      hostname = args[0];
    }
    catch (Exception e) {
      hostname = "http://localhost";
    }

    FetchURL doIt = new FetchURL();
    doIt.printResult(doIt.run(hostname));
  }
}
