/* DOS 窓オンリー */ import java.net.*; import java.io.*; import java.util.*; import java.lang.*; import java.util.regex.*; public class awk { static Pattern pattern; static Matcher matcher; static URL url; public static void main(String[] args) { String path = "http://www.asahi.com/index.html"; String inputLine; int counter = 0; byte[] cmd2 = {(byte)0x1b, (byte)0x40, (byte)0x1f, (byte)0x58, (byte)0x02, (byte)0x1f, (byte)0x28, (byte)0x67, (byte)0x1, (byte)0x2, (byte)0x1f, (byte)0x28, (byte)0x67, (byte)0x2, (byte)0x1, (byte)0x1b, (byte)0x74, (byte)0x1, (byte)0x1f, (byte)0x1, (byte)0xc, (byte)0x1f, (byte)0x28, (byte)0x67, (byte)0x40, (byte)0x1, (byte)0x1, (byte)0x1f, (byte)0x28, (byte)0x61, (byte)0x10, (byte)0x4, (byte)0x0, (byte)0x0, (byte)0x0, (byte)0x1, (byte)0x1f, (byte)0x03, (byte)0x1f, (byte)0x73, (byte)0x02, (byte)0x1f, (byte)0x6d, (byte)0x01, (byte)0x1f, (byte)0x24, (byte)0xfe, (byte)0x0, (byte)0x0, (byte)0x0 }; String xdata = new String(cmd2); XPortTX.XPortSend(xdata, 10); while (true) { try { url = new URL(path); } catch(MalformedURLException me) { System.out.println("MalformedURLException: " + me); } System.out.println("-----------------" + counter++ + "----------------"); try { InputStream in = url.openStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in, "EUCJP")); File file = new File("urlSJIS.html"); FileOutputStream os = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(os, "SJIS"); BufferedWriter bw = new BufferedWriter(osw); PrintWriter pw = new PrintWriter(bw); String lineo; while ((lineo = br.readLine()) != null) { pw.println(lineo); } pw.close(); FileInputStream is = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(is); BufferedReader bro = new BufferedReader(isr); while ((inputLine = bro.readLine()) != null) { //System.out.println(inputLine); pattern = Pattern.compile(""); matcher = pattern.matcher(inputLine); String rep = matcher.replaceAll(" "); pattern = Pattern.compile("[> <]+"); String[] line = pattern.split(rep); for (int i = 0; i < line.length; i++) { pattern = Pattern.compile(".*([0-9][0-9]:[0-9][0-9]).*"); matcher = pattern.matcher(line[i]); if (matcher.matches()) { // 直前がなんであるかをチェック pattern = Pattern.compile(".*html.*"); matcher = pattern.matcher(line[i -2]); if(matcher.matches()) { String onemsg = line[i - 1] + line[i]; onemsg = onemsg + " "; System.out.println(onemsg); XPortTX.XPortSend(onemsg, 10000); } } } } pw.close(); } catch(IOException ioe) { System.out.println("IOException: " + ioe); } } } } class XPortTX { public static void XPortSend (String msg, int sleep) { // XPort try{ Socket theSock = new Socket("192.168.0.55", 14000); // XPortへ接続 //System.out.println("Connencting...."); // 出力ストリーム と 入力ストリーム を設定 DataOutputStream sockout=new DataOutputStream(theSock.getOutputStream()); DataInputStream sockin =new DataInputStream(theSock.getInputStream()); //System.out.println("Connected"); sockout.write(msg.getBytes()); sockout.flush(); //System.out.println("Send"); sockout.close(); sockin.close(); theSock.close(); } catch(Exception e) { System.out.println("XPort Error!"); } // Wait 1sec try { Thread.sleep(sleep); // wait } catch (InterruptedException e) { ; } } }