Source:
<code>public void run(String format, String[] args) { super.run(format, args); mlParams = CmdLineUtil.loadTrainingParameters(params.getParams(), false); if (mlParams == null) { mlParams = ModelUtil.createDefaultTrainingParameters(); } List<EvaluationMonitor<LanguageDetectorSample>> listeners = new LinkedList<>(); if (params.getMisclassified()) { listeners.add(new LanguageDetectorEvaluationErrorListener()); } LanguageDetectorFineGrainedReportListener reportListener = null; File reportFile = params.getReportOutputFile(); OutputStream reportOutputStream = null; if (reportFile != null) { CmdLineUtil.checkOutputFile("Report Output File", reportFile); try { reportOutputStream = new FileOutputStream(reportFile); reportListener = new LanguageDetectorFineGrainedReportListener(reportOutputStream); listeners.add(reportListener); } catch (FileNotFoundException e) { throw createTerminationIOException(e); } } LanguageDetectorEvaluationMonitor[] listenersArr = listeners .toArray(new LanguageDetectorEvaluationMonitor[listeners.size()]); LanguageDetectorCrossValidator validator; try { LanguageDetectorFactory factory = LanguageDetectorFactory.create(params.getFactory()); validator = new LanguageDetectorCrossValidator(mlParams, factory, listenersArr); validator.evaluate(sampleStream, params.getFolds()); } catch (IOException e) { throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " + e.getMessage(), e); } finally { <START> try { <END> sampleStream.close(); } catch (IOException e) { } } System.out.println("done"); if (reportListener != null) { System.out.println("Writing fine-grained report to " + params.getReportOutputFile().getAbsolutePath()); reportListener.writeReport(); try { reportOutputStream.close(); } catch (IOException e) { } } System.out.println(); System.out.println("Accuracy: " + validator.getDocumentAccuracy() + "\n" + "Number of documents: " + validator.getDocumentCount()); }</code><technical_language>java resource handling here. I is current tool base class, change it</technical_language>

Target:
public void run(String format, String[] args) { super.run(format, args); mlParams = CmdLineUtil.loadTrainingParameters(params.getParams(), false); if (mlParams == null) { mlParams = ModelUtil.createDefaultTrainingParameters(); } List<EvaluationMonitor<LanguageSample>> listeners = new LinkedList<>(); if (params.getMisclassified()) { listeners.add(new LanguageDetectorEvaluationErrorListener()); } LanguageDetectorFineGrainedReportListener reportListener = null; File reportFile = params.getReportOutputFile(); OutputStream reportOutputStream = null; if (reportFile != null) { CmdLineUtil.checkOutputFile("Report Output File", reportFile); try { reportOutputStream = new FileOutputStream(reportFile); reportListener = new LanguageDetectorFineGrainedReportListener(reportOutputStream); listeners.add(reportListener); } catch (FileNotFoundException e) { throw createTerminationIOException(e); } } LanguageDetectorEvaluationMonitor[] listenersArr = listeners .toArray(new LanguageDetectorEvaluationMonitor[listeners.size()]); LanguageDetectorCrossValidator validator; try { LanguageDetectorFactory factory = LanguageDetectorFactory.create(params.getFactory()); validator = new LanguageDetectorCrossValidator(mlParams, factory, listenersArr); validator.evaluate(sampleStream, params.getFolds()); } catch (IOException e) { throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " + e.getMessage(), e); } finally { try { sampleStream.close(); } catch (IOException e) { } } System.out.println("done"); if (reportListener != null) { System.out.println("Writing fine-grained report to " + params.getReportOutputFile().getAbsolutePath()); reportListener.writeReport(); try { reportOutputStream.close(); } catch (IOException e) { } } System.out.println(); System.out.println("Accuracy: " + validator.getDocumentAccuracy() + "\n" + "Number of documents: " + validator.getDocumentCount()); }