Source:
public void trainOnlineQueries(final int configurationIndex) throws PerfEnforceException { String MOAFileName = Paths.get(onlineLearningPath, "moa.jar").toString(); String trainingFileName = Paths.get(onlineLearningPath, "training.arff").toString(); String modifiedTrainingFileName = Paths.get(onlineLearningPath, "training-modified-" + configurationIndex + ".arff") .toString(); String predictionsFileName = Paths.get(onlineLearningPath, "predictions" + configurationIndex + ".txt").toString(); try { PrintWriter outputWriter = new PrintWriter(modifiedTrainingFileName); outputWriter.close(); FileChannel src = new FileInputStream(trainingFileName).getChannel(); FileChannel dest = new FileOutputStream(modifiedTrainingFileName).getChannel(); dest.transferFrom(src, 0, src.size()); src.close(); dest.close(); FileWriter appendDataWriter = new FileWriter(modifiedTrainingFileName, true); for (String s : previousDataPoints) { appendDataWriter.write(s + "\n"); } String newPoint = getQueryFeature(configurationIndex, 0); appendDataWriter.write(newPoint + "\n"); appendDataWriter.close(); String moaCommand = String.format( "EvaluatePrequentialRegression -l (rules.functions.Perceptron -d -l %s) -s (ArffFileStream -f %s) -e (WindowRegressionPerformanceEvaluator -w 1) -f 1 -o %s", .04, modifiedTrainingFileName, predictionsFileName); String[] arrayCommand = new String[] {"java", "-classpath", MOAFileName, "moa.DoTask", moaCommand}; Process p = Runtime.getRuntime().exec(arrayCommand); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((reader.readLine()) != null) parsingOnlineFile(configurationIndex, predictionsFileName); } catch (Exception e) { throw new PerfEnforceException("Error during training"); } }

Target:
public void trainOnlineQueries(final int configurationIndex) throws PerfEnforceException { String MOAFileName = Paths.get(onlineLearningPath, "moa.jar").toString(); String trainingFileName = Paths.get(onlineLearningPath, "training.arff").toString(); String modifiedTrainingFileName = Paths.get(onlineLearningPath, "training-modified-" + configurationIndex + ".arff") .toString(); String predictionsFileName = Paths.get(onlineLearningPath, "predictions" + configurationIndex + ".txt").toString(); try { PrintWriter outputWriter = new PrintWriter(modifiedTrainingFileName); outputWriter.close(); FileChannel src = new FileInputStream(trainingFileName).getChannel(); FileChannel dest = new FileOutputStream(modifiedTrainingFileName).getChannel(); dest.transferFrom(src, 0, src.size()); src.close(); dest.close(); FileWriter appendDataWriter = new FileWriter(modifiedTrainingFileName, true); for (String s : previousDataPoints) { appendDataWriter.write(s + "\n"); } String newPoint = getQueryFeature(configurationIndex, 0); appendDataWriter.write(newPoint + "\n"); appendDataWriter.close(); String moaCommand = String.format( "EvaluatePrequentialRegression -l (rules.functions.Perceptron -d -l %s) -s (ArffFileStream -f %s) -e (WindowRegressionPerformanceEvaluator -w 1) -f 1 -o %s", .04, modifiedTrainingFileName, predictionsFileName); String[] arrayCommand = new String[] {"java", "-classpath", MOAFileName, "moa.DoTask", moaCommand}; Process p = Runtime.getRuntime().exec(arrayCommand); try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))) { while ((reader.readLine()) != null) } parsingOnlineFile(configurationIndex, predictionsFileName); } catch (Exception e) { throw new PerfEnforceException("Error during training"); } }