737 /**
738 * Thread-friendly class to read the output from a process until the stream
739 * is exhausted.
740 */
741 static class ProcessOutput implements Runnable {
742 ProcessOutput(InputStream from) {
743 in = new BufferedReader(new InputStreamReader(from));
744 out = new StringBuilder();
745 }
746
747 ProcessOutput start() {
748 new Thread(this).start();
749 return this;
750 }
751
752 @Override
753 public void run() {
754 try {
755 String line;
756 while ((line = in.readLine()) != null) {
757 out.append(line).append("\n");
758 }
759 } catch (IOException e) {
760 }
761 synchronized (this) {
762 done = true;
763 notifyAll();
764 }
765 }
766
767 synchronized void waitUntilDone() throws InterruptedException {
768 boolean interrupted = false;
769
770 // poll interrupted flag, while waiting for copy to complete
771 while (!(interrupted = Thread.interrupted()) && !done)
772 wait(1000);
773
774 if (interrupted)
775 throw new InterruptedException();
776 }
777
|
737 /**
738 * Thread-friendly class to read the output from a process until the stream
739 * is exhausted.
740 */
741 static class ProcessOutput implements Runnable {
742 ProcessOutput(InputStream from) {
743 in = new BufferedReader(new InputStreamReader(from));
744 out = new StringBuilder();
745 }
746
747 ProcessOutput start() {
748 new Thread(this).start();
749 return this;
750 }
751
752 @Override
753 public void run() {
754 try {
755 String line;
756 while ((line = in.readLine()) != null) {
757 out.append(line).append(lineSeparator);
758 }
759 } catch (IOException e) {
760 }
761 synchronized (this) {
762 done = true;
763 notifyAll();
764 }
765 }
766
767 synchronized void waitUntilDone() throws InterruptedException {
768 boolean interrupted = false;
769
770 // poll interrupted flag, while waiting for copy to complete
771 while (!(interrupted = Thread.interrupted()) && !done)
772 wait(1000);
773
774 if (interrupted)
775 throw new InterruptedException();
776 }
777
|