Пример #1
0
 public void run() {
   try {
     for (; ; ) {
       byte[] buf = new byte[8192];
       int l = out.read(buf);
       InputStreamReader r = new InputStreamReader(new ByteArrayInputStream(buf, 0, l));
       StringBuilder sb = new StringBuilder();
       for (; ; ) {
         int c = r.read();
         if (c == -1) {
           break;
         }
         sb.append((char) c);
       }
       if (sb.length() > 0) {
         terminal.write(sb.toString());
       }
       String s = terminal.read();
       if (s != null && s.length() > 0) {
         for (byte b : s.getBytes()) {
           in.write(b);
         }
       }
     }
   } catch (IOException e) {
     closed = true;
     e.printStackTrace();
   }
 }
Пример #2
0
    public SessionTerminal() throws IOException {
      try {
        this.terminal = new Terminal(TERM_WIDTH, TERM_HEIGHT);
        terminal.write("\u001b\u005B20\u0068"); // set newline mode on

        in = new PipedOutputStream();
        out = new PipedInputStream();
        PrintStream pipedOut = new PrintStream(new PipedOutputStream(out), true);

        final Subject subject = new Subject();
        subject.getPrincipals().add(new UserPrincipal("karaf"));
        Console console =
            consoleFactory.create(
                commandProcessor,
                new PipedInputStream(in),
                pipedOut,
                pipedOut,
                new WebTerminal(TERM_WIDTH, TERM_HEIGHT),
                null);
        consoleFactory.startConsoleAs(console, subject);
      } catch (IOException e) {
        e.printStackTrace();
        throw e;
      } catch (Exception e) {
        e.printStackTrace();
        throw (IOException) new IOException().initCause(e);
      }
      new Thread(this).start();
    }