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;
   }
 }
    public SessionTerminal(CommandProcessor commandProcessor, ThreadIO threadIO)
        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);

        console =
            createConsole(
                commandProcessor, new PipedInputStream(in), pipedOut, threadIO, getBundleContext());
        CommandSession session = factory.getSession(console);
        session.put("APPLICATION", System.getProperty("karaf.name", "root"));
        // TODO: user should likely be the logged in user, eg we can grab that from the user servlet
        session.put("USER", "karaf");
        session.put("COLUMNS", Integer.toString(TERM_WIDTH));
        session.put("LINES", Integer.toString(/*TERM_HEIGHT*/ 39));
      } catch (IOException e) {
        LOG.info("Exception attaching to console", e);
        throw e;
      } catch (Exception e) {
        LOG.info("Exception attaching to console", e);
        throw (IOException) new IOException().initCause(e);
      }
      new Thread((Runnable) console).start();
      new Thread(this).start();
    }
Beispiel #3
0
    public SessionTerminal(CommandProcessor commandProcessor, ThreadIO threadIO)
        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);

        console =
            new Console(
                commandProcessor,
                threadIO,
                new PipedInputStream(in),
                pipedOut,
                pipedOut,
                new WebTerminal(TERM_WIDTH, TERM_HEIGHT),
                null,
                null);
        CommandSession session = console.getSession();
        session.put("APPLICATION", System.getProperty("karaf.name", "root"));
        session.put("USER", "karaf");
        session.put("COLUMNS", Integer.toString(TERM_WIDTH));
        session.put("LINES", Integer.toString(TERM_HEIGHT));
      } catch (IOException e) {
        LOG.info("Exception attaching to console", e);
        throw e;
      } catch (Exception e) {
        LOG.info("Exception attaching to console", e);
        throw (IOException) new IOException().initCause(e);
      }
      new Thread(console).start();
      new Thread(this).start();
    }
 public String handle(String str, boolean forceDump) throws IOException {
   try {
     if (str != null && str.length() > 0) {
       String d = terminal.pipe(str);
       for (byte b : d.getBytes()) {
         in.write(b);
       }
       in.flush();
     }
   } catch (IOException e) {
     closed = true;
     throw e;
   }
   try {
     return terminal.dump(10, forceDump);
   } catch (InterruptedException e) {
     throw new InterruptedIOException(e.toString());
   }
 }