Пример #1
1
    public void run() {
      try {
        // An arbitrary buffer size.
        char[] chbuf = new char[4096];

        while (keepRunning) {
          int numchars = reader.read(chbuf);
          if (numchars == -1) {
            keepRunning = false;
          } else if (keepRunning) {
            writer.write(chbuf, 0, numchars);
            if (!reader.ready()) {
              writer.flush();
            }
          }
        }
      } catch (IOException ex) {
        println("Error when linking JVM output to terminal window input.");
      }
    }
Пример #2
0
 static String outputOf(Reader r) throws IOException {
   final StringBuilder sb = new StringBuilder();
   final char[] buf = new char[1024];
   int n;
   while ((n = r.read(buf)) > 0) sb.append(buf, 0, n);
   return sb.toString();
 }