/* CGI起動クラス Ver 0.00 */ /* */ /* */ /* by Atsushi 98/3/14 */ package lib.net; import java.io.*; import java.net.URL; import java.net.URLConnection; public class TextCGI extends Object { /* --- Field --- */ private URL address; private URLConnection cgi; /* --- Constructor --- */ public TextCGI(URL address) { this.address=address; } /* --- 接続 --- */ public void connect() throws IOException { cgi=address.openConnection(); cgi.setUseCaches(false); cgi.setRequestProperty("Content-type","text/plain"); cgi.setDoInput(true); } /* --- Submit --- */ public String post(String input) throws IOException { BufferedWriter writer=null; cgi.setDoOutput(true); try { writer=new BufferedWriter( new OutputStreamWriter(cgi.getOutputStream(),"SJIS")); writer.write(input); writer.close(); } catch (IOException e) { try { if (writer!=null) writer.close(); } catch (IOException e2) {} throw e; } return get(); } public String get() throws IOException { BufferedReader reader=null; String output; String line; output=""; try { reader=new BufferedReader( new InputStreamReader(cgi.getInputStream(),"SJIS")); while (true) { line=reader.readLine(); if (line==null) break; output=output+line+"\n"; } reader.close(); } catch (IOException e) { try { if (reader!=null) reader.close(); } catch (IOException e2) {} throw e; } return output; } }