Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void receive() {
- Runnable serverReceiver = new Runnable() {
- public void run() {
- // Generally the isr (InputStreamReader) is set to null after Process.waitFor() is finished.
- if (isr != null) {
- /*try {*/
- // Generally the br (BufferedReader) is set to null after Process.waitFor() is finished.
- //if ((isr.ready()) && (br != null)) {
- if (br != null) {
- /*try {*/
- StringBuilder line = new StringBuilder();
- System.out.println("About to read");
- boolean doneReading = false;
- // Reads from the BufferedReader while it's got stuff to share.
- /*while(br.ready()) {
- try {
- int character = br.read();
- if (character != -1) {
- if ((!Character.toString(Character.toChars(character)[0]).equals(">")) && (!Character.toString(Character.toChars(character)[0]).equals("\n"))) {
- line.append(Character.toChars(character));
- }
- }
- } catch (IOException e) {
- System.out.println("IOException on br.read()");
- }
- }*/
- while (!doneReading) {
- try {
- int character = br.read();
- if (character != -1) {
- if ((!Character.toString(Character.toChars(character)[0]).equals(">")) && (!Character.toString(Character.toChars(character)[0]).equals("\n"))) {
- line.append(Character.toChars(character));
- }
- }
- } catch (IOException e) {
- System.out.println("IOException on br.read()");
- }
- }
- System.out.println(line.toString()); // Debug output
- // Replace a blank console output but add to a non-blank one
- if (consoleOutput.getText().equals("")) {
- //System.out.println("1 time");
- consoleOutput.setText(line.toString());
- }
- // If consoleOutput already has data, add to it
- else {
- consoleOutput.setText(consoleOutput.getText() + line.toString());
- }
- /*} catch (IOException e) {
- System.out.println("IOException on br.ready()");
- }*/
- }
- /*} catch (IOException e) {
- System.out.println("IOException on isr.ready()");
- }*/
- }
- }
- };
- SwingUtilities.invokeLater(serverReceiver);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement