RunSchemaSpy.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package schemaspygui;
  2. import java.io.*;
  3. import java.io.InputStreamReader;
  4. //Catches every error output from SchemaSpy
  5. /**
  6. *
  7. * @author joachim uhl; mailto:admin@joachim-uhl.de; http://www.joachim-uhl.de/projekte/schemaspygui/
  8. */
  9. public class RunSchemaSpy implements Runnable {
  10. private SchemaSpyGUIApp gui;
  11. private String command;
  12. private String displ_command;
  13. public RunSchemaSpy(SchemaSpyGUIApp gui, String run_command, String display_command) {
  14. this.gui = gui;
  15. this.command = run_command;
  16. this.displ_command = display_command;
  17. }
  18. public void run( ) {
  19. try {
  20. gui.setOutputText("This is the command (password not displayed!) SchemaSpyGUI has generated:" +"\n");
  21. gui.setOutputText(displ_command +"\n");
  22. gui.setOutputText("\n");
  23. Process d = Runtime.getRuntime().exec(command);
  24. ErrStreamOut errOut = new ErrStreamOut(d, gui);
  25. InputStreamOut inOut = new InputStreamOut(d, gui);
  26. Thread terrOut = new Thread(errOut);
  27. Thread tinOut = new Thread(inOut);
  28. terrOut.setName("terrOut");
  29. terrOut.start();
  30. tinOut.setName("tinOut");
  31. tinOut.start();
  32. } catch ( Exception ioe ) {
  33. System.err.println( "IO error: " + ioe );
  34. ioe.printStackTrace();
  35. }
  36. }
  37. }
  38. class ErrStreamOut implements Runnable {
  39. private Process p;
  40. private SchemaSpyGUIApp gui;
  41. public ErrStreamOut(Process d, SchemaSpyGUIApp gui) {
  42. this.p = d;
  43. this.gui = gui;
  44. }
  45. public void run() {
  46. try {
  47. BufferedReader in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
  48. String s;
  49. while ((s = in.readLine()) != null) {
  50. gui.setOutputText(s +"\n");
  51. }
  52. int exitVal = p.waitFor();
  53. gui.setOutputText("E=" + exitVal);
  54. in.close();
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. }
  60. //Catches every "normal" output from SchemaSpy
  61. class InputStreamOut implements Runnable {
  62. private Process p;
  63. private SchemaSpyGUIApp gui;
  64. public InputStreamOut(Process d, SchemaSpyGUIApp gui) {
  65. this.p = d;
  66. this.gui = gui;
  67. }
  68. public void run() {
  69. try {
  70. BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
  71. //String s;
  72. int c;
  73. /*while ((s = in.readLine()) != null)
  74. {GuiSchema.setText(s +"\n");}
  75. int exitVal = p.waitFor();
  76. GuiSchema.setText("" +exitVal);
  77. */
  78. while ((c = in.read()) != -1) {
  79. /*String aChar = new Character((char)c).toString();
  80. GuiSchema.setText(aChar);*/
  81. gui.setOutputText(String.valueOf(Character.toChars(c)));
  82. }
  83. int exitVal = p.waitFor();
  84. gui.setOutputText("I=" + exitVal);
  85. in.close();
  86. // Launch the result when finish if checked and No Errors
  87. if (exitVal == 0 && gui.getAutoLaunchInfo()) {gui.startShowOutput();}
  88. } catch (Exception e) {
  89. e.printStackTrace();
  90. }
  91. }
  92. }