Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package net.minecraft.client; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.PipedInputStream; import java.io.PipedOutputStream; import javax.swing.JTextArea; import javax.swing.SwingWorker; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecuteResultHandler; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.ExecuteResultHandler; import org.apache.commons.exec.Executor; import org.apache.commons.exec.PumpStreamHandler; /** * * @author Taconut */ public class MineExec extends SwingWorker { public String mineCmd; public JTextArea logWindow; public Object[] nbDebug; public String password; public String uname; public boolean watchCfg; public MineExec(String cmd, JTextArea logWindow, Object[] nbDebug, String uname, String password, boolean watchCfg) { mineCmd = cmd; this.logWindow = logWindow; this.nbDebug = nbDebug; this.password = password; this.uname = uname; this.watchCfg = watchCfg; } @Override protected Integer doInBackground() throws IOException, InterruptedException { Executor exe = new DefaultExecutor(); CommandLine mineExec = CommandLine.parse(mineCmd); PipedOutputStream stdout = new PipedOutputStream(); PipedOutputStream stderr = new PipedOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr); exe.setStreamHandler(streamHandler); MinecraftApplet configCrusher = new MinecraftApplet(); try { File target = new File(VersionInfo.getTechnicFolder()); BufferedInputStream biserr = new BufferedInputStream(new PipedInputStream(stderr)); ExecuteResultHandler rh = new DefaultExecuteResultHandler(); exe.execute(mineExec, rh); BufferedReader reader = new BufferedReader(new InputStreamReader(biserr)); configCrusher.minecraftLoaded(); String line = reader.readLine(); logWindow.append(line + "\n"); int dupLen = 0; int dupMax = 25; while (line != null) { String line2 = reader.readLine(); if ((line2.contains("Aether") || line2.contains("aether") && watchCfg && new File(target + File.separator + VersionInfo.getModpackName(), "MenuAPI.properties") .exists())) { configCrusher.prepareConfigs(); } if ((Boolean) nbDebug[2]) { if (!line.equals(line2) || dupLen >= dupMax) { if (dupLen > 0) { logWindow.append(line + "(" + dupLen + ")\n"); } else { if (!line.equals(line2)) { logWindow.append(line2 + "\n"); } } dupLen = 0; } else { dupLen++; } line = line2; } else { logWindow.append(line2 + "\n"); line = line2; } } } catch (IOException e) { e.printStackTrace(); } if ((Integer) (nbDebug[1]) <= 1) { configCrusher.remExtras(); configCrusher.minecraftClosed(password); } return 1; } }