<commit_before>package org.disco.easyb.report

import org.disco.easyb.listener.ResultsCollector
import groovy.text.SimpleTemplateEngine

class HtmlReportWriter implements ReportWriter {
    private String location


    HtmlReportWriter(String location) {
        this.location = location
    }

    public void writeReport(ResultsCollector results) {

        writeResourceToDisk("resource/thirdparty/prototype", "prototype.js")

        ['img01.gif','img02.jpg','img03.jpg','img04.jpg','img05.jpg','img06.jpg','spacer.gif','report.css'].each {
            writeResourceToDisk("resource/reports", "easyb_${it}")
        }

        InputStream mainTemplateInputStream = this.class.getClassLoader().getResourceAsStream("resource/reports/easyb_report_main.tmpl");

        def outputReportBufferedWriter = new File(location).newWriter();
        def templateBinding = ["results": results, "reportWriter": outputReportBufferedWriter]
        def templateEngine = new SimpleTemplateEngine()
        def reportTemplate = templateEngine.createTemplate(mainTemplateInputStream.newReader()).make(templateBinding)
        reportTemplate.writeTo(outputReportBufferedWriter)

    }

    private writeResourceToDisk(String resourceLocation, resourceName) {
        InputStream inputStream = this.class.getClassLoader().getResourceAsStream("${resourceLocation}/${resourceName}");
        if (inputStream != null) {
            FileOutputStream resourceWriter = new FileOutputStream("${locationDir}${File.separator}${resourceName}")
            inputStream.eachByte {singleByte ->
                resourceWriter.write(singleByte)
            }
            resourceWriter.close()
        }
    }

    private getLocationDir() {
        String normalizedPath =  new File(location).canonicalPath

        if (normalizedPath.contains("/")) {
            return normalizedPath.substring(0, normalizedPath.lastIndexOf("/"))
        } else {
            return "."
        }
    }

}<commit_msg>another change to fix the windows report writing issues<commit_after>package org.disco.easyb.report

import org.disco.easyb.listener.ResultsCollector
import groovy.text.SimpleTemplateEngine

class HtmlReportWriter implements ReportWriter {
    private String location


    HtmlReportWriter(String location) {
        this.location = location
    }

    public void writeReport(ResultsCollector results) {

        writeResourceToDisk("resource/thirdparty/prototype", "prototype.js")

        ['img01.gif','img02.jpg','img03.jpg','img04.jpg','img05.jpg','img06.jpg','spacer.gif','report.css'].each {
            writeResourceToDisk("resource/reports", "easyb_${it}")
        }

        InputStream mainTemplateInputStream = this.class.getClassLoader().getResourceAsStream("resource/reports/easyb_report_main.tmpl");

        def outputReportBufferedWriter = new File(location).newWriter();
        def templateBinding = ["results": results, "reportWriter": outputReportBufferedWriter]
        def templateEngine = new SimpleTemplateEngine()
        def reportTemplate = templateEngine.createTemplate(mainTemplateInputStream.newReader()).make(templateBinding)
        reportTemplate.writeTo(outputReportBufferedWriter)

    }

    private writeResourceToDisk(String resourceLocation, resourceName) {
        InputStream inputStream = this.class.getClassLoader().getResourceAsStream("${resourceLocation}/${resourceName}");
        if (inputStream != null) {
            FileOutputStream resourceWriter = new FileOutputStream("${locationDir}${File.separator}${resourceName}")
            inputStream.eachByte {singleByte ->
                resourceWriter.write(singleByte)
            }
            resourceWriter.close()
        }
    }

    private getLocationDir() {
        String normalizedPath =  new File(location).canonicalPath

      if (normalizedPath.contains("\\")) {
        return normalizedPath.substring(0, normalizedPath.lastIndexOf("\\"))
      } else if (location.contains("/")) {
        return normalizedPath.substring(0, normalizedPath.lastIndexOf("/"))
      } else {
        return "."
      }

    }


}
{'fraction_non_alphanumeric': 0.11075872163942425, 'fraction_numerical': 0.006586972432300561, 'mean_word_length': 3.475982532751092, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5009278', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1015, 'n_words': 170}