Package com.kolakcc.loljclient.controller

Source Code of com.kolakcc.loljclient.controller.DebugController

package com.kolakcc.loljclient.controller;

import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.List;
import java.util.Scanner;

import javax.swing.SwingWorker;

import com.kolakcc.loljclient.view.DebugView;


public class DebugController extends KolaController {
  DebugView view;
  public DebugController() {
    view = new DebugView();
    this.setView(view);
   
    try {
      final PipedInputStream outPipe = new PipedInputStream();
      System.setOut(new PrintStream(new PipedOutputStream(outPipe), true));
     
      new SwingWorker<Void, String>() {
            protected Void doInBackground() throws Exception {
                Scanner s = new Scanner(outPipe);
                while (s.hasNextLine()) publish(s.nextLine() + "\n");
                s.close();
                return null;
            }
            protected void process(List<String> chunks) {
                for (String line : chunks) view.addOutLine(line);
            }
        }.execute();
       

      final PipedInputStream errPipe = new PipedInputStream();
      System.setErr(new PrintStream(new PipedOutputStream(errPipe), true));
     
      new SwingWorker<Void, String>() {
            protected Void doInBackground() throws Exception {
                Scanner s = new Scanner(errPipe);
                while (s.hasNextLine()) publish(s.nextLine() + "\n");
                s.close();
                return null;
            }
            protected void process(List<String> chunks) {
                for (String line : chunks) view.addErrLine(line);
            }
        }.execute();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
TOP

Related Classes of com.kolakcc.loljclient.controller.DebugController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.