package network.server; import network.Requisition; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.Socket; import java.util.List; import java.util.StringTokenizer; import java.util.Vector; public class Control extends Thread { private Socket connection; private static int count=0; ObjectOutputStream objoutstream; ObjectInputStream objinstream; public Control(Socket s) { connection = s; } public void run() { try { Requisition req_received,req_answer; // objetos que permitem controlar fluxo de comunicação this.objoutstream = new ObjectOutputStream(connection.getOutputStream() ); this.objinstream = new ObjectInputStream(connection.getInputStream() ); System.out.println("Receiving proof obligation..."); req_received = (Requisition) this.objinstream.readObject(); System.out.println("The prover is working"); req_answer = this.callprover(req_received); this.objoutstream.writeObject(req_answer); System.out.println("Answer sended!"); this.connection.close(); } catch (Exception e) { e.printStackTrace(); } } protected Requisition callprover(Requisition req) { Requisition req_answer = new Requisition(); StringBuffer output = new StringBuffer(); String path_po_file = new String(java.lang.System.getProperty("java.io.tmpdir") + File.separator+"proof"+(count++)+".smt"); // write the proof obligation to file try{ FileWriter fstream = new FileWriter(path_po_file); BufferedWriter out = new BufferedWriter(fstream); String pO = req.getProofobligation(); String novapO = ""; for (int i=0; i< pO.length() ;i++) { if (pO.charAt(i) == 13) { novapO = novapO + ' '; } else { novapO = novapO + pO.charAt(i); } } out.write(novapO); out.close(); } catch (IOException e) { System.err.println("Error writing the file from proof obligation."); } // call the prover try { String[] tmp = req.getProvername().split(" "); String [] commands = new String[ tmp.length + 1 ]; for(int i=0;i 0) { respostaHarvey = lines[lines.length - 1]; } req_answer.setResult( new String( respostaHarvey) ); return req_answer; } private static String[] returnLines(String str) { String lineSep = System.getProperty("line.separator"); StringTokenizer st = new StringTokenizer(str,lineSep); List list = new Vector(); while (st.hasMoreTokens()) { list.add(st.nextToken()); } String[] retorno = list.toArray(new String[0]); return retorno; } }