Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.62 KB | None | 0 0
  1.     public void receive() {
  2.         Runnable serverReceiver = new Runnable() {
  3.             public void run() {
  4.                 // Generally the isr (InputStreamReader) is set to null after Process.waitFor() is finished.
  5.                 if (isr != null) {
  6.                     /*try {*/
  7.                         // Generally the br (BufferedReader) is set to null after Process.waitFor() is finished.
  8.                         //if ((isr.ready()) && (br != null)) {
  9.                         if (br != null) {
  10.                             /*try {*/
  11.                                 StringBuilder line = new StringBuilder();
  12.                                 System.out.println("About to read");
  13.                                 boolean doneReading = false;
  14.                                 // Reads from the BufferedReader while it's got stuff to share.
  15.                                 /*while(br.ready()) {
  16.                                     try {
  17.                                         int character = br.read();
  18.                                         if (character != -1) {
  19.                                             if ((!Character.toString(Character.toChars(character)[0]).equals(">")) && (!Character.toString(Character.toChars(character)[0]).equals("\n"))) {
  20.                                                 line.append(Character.toChars(character));
  21.                                             }
  22.                                         }
  23.                                     } catch (IOException e) {
  24.                                         System.out.println("IOException on br.read()");
  25.                                     }
  26.                                 }*/
  27.                                 while (!doneReading) {
  28.                                     try {
  29.                                         int character = br.read();
  30.                                         if (character != -1) {
  31.                                             if ((!Character.toString(Character.toChars(character)[0]).equals(">")) && (!Character.toString(Character.toChars(character)[0]).equals("\n"))) {
  32.                                                 line.append(Character.toChars(character));
  33.                                             }
  34.                                         }
  35.                                     } catch (IOException e) {
  36.                                         System.out.println("IOException on br.read()");
  37.                                     }
  38.                                 }
  39.                                 System.out.println(line.toString());        // Debug output
  40.  
  41.                                 // Replace a blank console output but add to a non-blank one
  42.                                 if (consoleOutput.getText().equals("")) {
  43.                                     //System.out.println("1 time");
  44.                                     consoleOutput.setText(line.toString());
  45.                                 }
  46.                                     // If consoleOutput already has data, add to it
  47.                                 else {
  48.                                     consoleOutput.setText(consoleOutput.getText() + line.toString());
  49.                                 }
  50.                                
  51.                             /*} catch (IOException e) {
  52.                                 System.out.println("IOException on br.ready()");
  53.                             }*/
  54.                         }
  55.                     /*} catch (IOException e) {
  56.                         System.out.println("IOException on isr.ready()");
  57.                     }*/
  58.                 }
  59.             }
  60.         };
  61.         SwingUtilities.invokeLater(serverReceiver);
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement