01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.unittest.cogent;
12:
13: import java.io.*;
14:
15: public class DecisionProcedureCogent {
16:
17: public static CogentResult execute(String input) throws IOException {
18: Process p = Runtime.getRuntime().exec(
19: new String[] { "rm", "-f", "/tmp/cogentOut" });
20: try {
21: p.waitFor();
22: } catch (InterruptedException e) {
23: System.out.println(e);
24: //do nothing
25: }
26: File cogentOut = new File("/tmp/cogentOut");
27: File file = File.createTempFile("key-cogent", null);
28: PrintWriter out = new PrintWriter(new FileWriter(file));
29: out.println(input);
30: out.close();
31:
32: p = Runtime
33: .getRuntime()
34: .exec(
35: new String[] { "cogent", file.getPath() /*+ " >/tmp/cogentOut"*/});
36: InputStream error = p.getErrorStream();
37: String response = read(error);
38: InputStream in = p.getInputStream();
39: response += read(in);
40: try {
41: p.waitFor();
42: } catch (InterruptedException e) {
43: System.out.println(e);
44: //do nothing
45: }
46: in.close();
47: error.close();
48:
49: file.delete();
50:
51: return new CogentResult(response);
52: }
53:
54: /** Read the input until end of file and return contents in a
55: * single string containing all line breaks. */
56: protected static String read(InputStream in) throws IOException {
57: String lineSeparator = System.getProperty("line.separator");
58: BufferedReader reader = new BufferedReader(
59: new InputStreamReader(in));
60: StringBuffer sb = new StringBuffer();
61: String line;
62: while ((line = reader.readLine()) != null) {
63: sb.append(line).append(lineSeparator);
64: }
65: return sb.toString();
66: }
67:
68: }
|