FileDocCategorySizeDatePackage
Weather.javaAPI DocExample2081Sun Feb 15 20:44:14 GMT 2004None

Weather

public class Weather extends Object
Connect to a METCAST station and print the results

Fields Summary
public static final String
request
public static final String
SERVER
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		Weather wx = new Weather();
		wx.process();
	
protected voidprocess()


		System.out.println("Setting up URLConnection");

		URL u = new URL(SERVER);

		URLConnection cx = u.openConnection();
		cx.setContentHandlerFactory(new ContentHandlerFactory() {
			public ContentHandler createContentHandler(String type) {
				if (type.startsWith("text/x-omf"))
					return new OMFHandler();
				return null;
			}
		});

		cx.setDoInput(true);
		cx.setDoOutput(true);
		cx.setAllowUserInteraction(false);

		DataOutputStream os =
			new DataOutputStream(cx.getOutputStream());

		System.out.println("Connecting the URLConnection");
		cx.connect();

		System.out.println("Request is:");
		System.out.println(request);

		System.out.println("Sending Request");
		os.writeBytes("mbl-stmt=" + URLEncoder.encode(request));
		os.flush();

		System.out.println("Getting the Response");
		
		Object response = cx.getContent();
		if (response instanceof InputStream)
			response = FileIO.inputStreamToString((InputStream)response);
		System.out.println(response);