Convert EARL result into HTML report.

@param outputDir
Location of the test result.
@return
Return the output file.
@throws FileNotFoundException
Throws exception if file is not available.
16518
public static File earlHtmlReport( String outputDir )
                    throws FileNotFoundException {

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        String resourceDir = cl.getResource( "com/occamlab/te/earl/lib" ).getPath();
        String earlXsl = cl.getResource( "com/occamlab/te/earl_html_report.xsl" ).toString();

        File htmlOutput = new File( outputDir, "result" );
        htmlOutput.mkdir();
        LOGR.fine( "HTML output is written to directory " + htmlOutput );
        File earlResult = new File( outputDir, "earl-results.rdf" );

        try {
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer( new StreamSource( earlXsl ) );
            transformer.setParameter( "outputDir", htmlOutput );
            File indexHtml = new File( htmlOutput, "index.html" );
            indexHtml.createNewFile();
            FileOutputStream outputStream = new FileOutputStream( indexHtml );
            transformer.transform( new StreamSource( earlResult ), new StreamResult( outputStream ) );
            // Foritfy Mod: Close the outputStream releasing its resources
            outputStream.close();
            FileUtils.copyDirectory( new File( resourceDir ), htmlOutput );
        } catch ( Exception e ) {
            LOGR.log( Level.SEVERE, "Transformation of EARL to HTML failed.", e );
            throw new RuntimeException( e );
        }
        if ( !htmlOutput.exists() ) {
            throw new FileNotFoundException( "HTML results not found at " + htmlOutput.getAbsolutePath() );
        }
        return htmlOutput;
    }
14415
public File outputDir(File src, File explicitOutputDir, String mapperName) throws IOException {
        File outputDir;
        int prev;
        int idx;
        File subDir;

        if (explicitOutputDir == null) {
            outputDir = src.getParentFile();
        } else {
            outputDir = explicitOutputDir;
            idx = mapperName.indexOf('.');
            prev = 0;
            while (idx != -1) {
                subDir = new File(outputDir, mapperName.substring(prev, idx));
                if (!subDir.isDirectory()) {
                    if (!subDir.mkdir()) {
                        throw new IOException("cannot create directory: " + subDir);
                    }
                }
                prev = idx + 1;
                idx = mapperName.indexOf('.', prev);
                outputDir = subDir;
            }
        }
        return outputDir;
    }
946577
@Override
    public InputStream getInputStream() throws IOException {
        if (!exists()) {
            throw new FileNotFoundException(getPath() + " (no such file or directory)");
        }
        if (Files.isDirectory(this.path)) {
            throw new FileNotFoundException(getPath() + " (is a directory)");
        }
        return Files.newInputStream(this.path);
    }
456785
private File createNewFile(File outputDir, String prefix, String extension) throws IOException {
        String dateTime = new SimpleDateFormat("yyyyMMdd.HHmmss").format(new Date());
        File outputFile;
        do {
            String pid = PID == null ? "" : PID + '.';
            int sequenceNumber = nextSequenceNumber.getAndIncrement();
            outputFile = new File(outputDir, String.format("%s.%s.%s%04d.%s", prefix, dateTime, pid, sequenceNumber, extension));
        } while (outputFile.exists());

        return outputFile;
    }
905144
public static void writeStreamToFile(InputStream isr, String fileName, String outputFolder) throws IOException {
        logger.entering(new Object[] { isr, fileName, outputFolder });
        FileUtils.copyInputStreamToFile(isr, new File(outputFolder + "/" + fileName));
        logger.exiting();
    }
260623
public void generateDataUriCss(String dir) throws IOException {
		final String path = (dir == null) ? "" : dir + "/";
		final PrintWriter out = new PrintWriter(path + "DataUriCss.html");

		try {
			out.append("<html>\n<head>\n\t<style>");

			for (OptimizerResult result : results) {
				final String name = result.fileName.replaceAll("[^A-Za-z0-9]", "_");
				out.append('#').append(name).append(" {\n")
						.append("\tbackground: url(\"data:image/png;base64,")
						.append(result.dataUri).append("\") no-repeat left top;\n")
						.append("\twidth: ").append(String.valueOf(result.width)).append("px;\n")
						.append("\theight: ").append(String.valueOf(result.height)).append("px;\n")
						.append("}\n");
			}
			out.append("\t</style>\n</head>\n<body>\n");

			for (OptimizerResult result : results) {
				final String name = result.fileName.replaceAll("[^A-Za-z0-9]", "_");
				out.append("\t<div id=\"").append(name).append("\"></div>\n");
			}

			out.append("</body>\n</html>");
		} finally {
			if (out != null) {
				out.close();
			}
		}
	}
1038232
private String getJUnitReportsFolder() {
        if (ClassUtils.isPresent("org.testng.annotations.Test", getClass().getClassLoader())) {
            return "test-output" + File.separator + "junitreports";
        } else if (ClassUtils.isPresent("org.junit.Test", getClass().getClassLoader())) {
            JUnitReporter jUnitReporter = new JUnitReporter();
            return jUnitReporter.getReportDirectory() + File.separator + jUnitReporter.getOutputDirectory();
        } else {
            return new LoggingReporter().getReportDirectory();
        }
    }
133835
public static FileWriter createFile(String name, String outDir) throws IOException
   {
      File path = new File(outDir);
      if (!path.exists())
      {
         if (!path.mkdirs())
            throw new IOException("outdir can't be created");
      }

      File file = new File(path.getAbsolutePath() + File.separatorChar + name);

      if (file.exists())
      {
         if (!file.delete())
            throw new IOException("there is exist file, please check");
      }

      return new FileWriter(file);
   }
547937
public Path getOutputDirectory()
    {
        File file = getOptionValue(OutputPathOption.NAME);
        return file == null ? null : file.toPath();
    }
288861
public function createOutputDir()
    {
        $outputDir = $this->configuration->get('output');

        if (!is_writable($outputDir)) {
            @mkdir($outputDir, 0777, true);

            if (!is_writable($outputDir)) {
                throw new \RuntimeException("Output directory {$outputDir} is not writable.");
            }
        }
    }
245205
public File output() throws IOException {
        File o = new File(output);
        if (!o.exists() && !o.mkdirs()) {
            throw new IOException("Unable to create output folder '" + output + "'");
        }
        return o;
    }
274430
public static File getWritableDirectoryWithFailovers(String... directories) throws FileNotFoundException {
    File logDir = null;
    for(String directory : directories) {
      if(directory != null) {
        try {
          logDir = ensureDirectoryWriteable(new File(directory));
        } catch(FileNotFoundException e) {
          log.debug("Failed to get writeable directory: "+directory, e);
          continue;
        }
        break;
      }
    }
    if(logDir == null) {
      throw new FileNotFoundException("Could not get a writeable directory!");
    }
    return logDir;
  }
559915
@Override
	public synchronized void createReport() throws IOException {
		if (reportLines.isEmpty()) {
			log.debug("No data to report. Skipping report generation.");
			return;
		}

		File reportFile = new File(archiveDir.get(), createFileName());

		log.debug("Writing report to file: {}", reportFile);

		String header = getHeaderLine();
		if (header != null) {
			reportLines.addFirst(header);
		}
		FileUtils.writeLines(reportFile, charset == null ? defaultCharset.name() : charset.name(), reportLines);

		reportLines.clear();
	}
808320
function getOutputFile(file, outputDir) {
  const fileName = path.basename(file).replace('.scss', '.css');
  return path.join(outputDir, fileName);
}
506108
def to_file(self, slug, folderpath=None, header=None, footer=None):
        
        if folderpath is None:
            if self.report_path is None:
                self.err(
                    "Please set the report_path parameter or pass a path in arguments")
                return
            folderpath = self.report_path
        else:
            self.report_path = folderpath
        html = self._get_header(header)
        if html is None or html == "":
            self.err(self.to_file, "Can not get html header")
        for report in self.reports:
            if "html" not in report:
                self.err("No html for report " + report)
                self.reports = self.report_engines = []
                return
            html += report["html"]
        html += self._get_footer(footer)
        try:
            path = self._write_file(slug, folderpath, html)
            path = "file://" + path
        except Exception as e:
            self.err(e, self.to_file, "Can not save report to file")
            return
        self.reports = []
        self.report_engines = []
        if self.notebook is True:
            link = '<a href="' + path + '" target="_blank">' + path + '</a>'
            return display(HTML(link))
97843
public static void generate(Path outputDir) throws IOException {
    DataReader reader = DataReader.get();
    CalendarCodeGenerator datetimeGenerator = new CalendarCodeGenerator();
    Map<LocaleID, ClassName> dateClasses = datetimeGenerator.generate(outputDir, reader);

    PluralCodeGenerator pluralGenerator = new PluralCodeGenerator();
    pluralGenerator.generate(outputDir, reader);

    NumberCodeGenerator numberGenerator = new NumberCodeGenerator();
    Map<LocaleID, ClassName> numberClasses = numberGenerator.generate(outputDir, reader);
    
    LanguageCodeGenerator languageGenerator = new LanguageCodeGenerator();
    languageGenerator.generate(outputDir, reader);
    
    MethodSpec registerCalendars = indexFormatters("registerCalendars", "registerCalendarFormatter", dateClasses);
    MethodSpec registerNumbers = indexFormatters("registerNumbers", "registerNumberFormatter", numberClasses);
    
    MethodSpec constructor = MethodSpec.constructorBuilder()
        .addModifiers(PRIVATE)
        .build();

    FieldSpec instance = FieldSpec.builder(CLDR, "instance", PRIVATE, STATIC, FINAL)
        .build();

    MethodSpec getter = MethodSpec.methodBuilder("get")
        .addModifiers(PUBLIC, STATIC)
        .returns(CLDR)
        .addStatement("return instance")
        .build();

    TypeSpec.Builder type = TypeSpec.classBuilder("CLDR")
        .addModifiers(PUBLIC)
        .superclass(CLDR_BASE)
        .addMethod(constructor)
        .addMethod(getter)
        .addMethod(registerCalendars)
        .addMethod(registerNumbers);

    Set<LocaleID> availableLocales = reader.availableLocales()
        .stream()
        .map(s -> LocaleID.parse(s))
        .collect(Collectors.toSet());
    
    createLocales(type, reader.defaultContent(), availableLocales);
    createLanguageAliases(type, reader.languageAliases());
    createTerritoryAliases(type, reader.territoryAliases());
    createLikelySubtags(type, reader.likelySubtags());
    createCurrencies(type, numberGenerator.getCurrencies(reader));
    
    addPluralRules(type);

    // Initialize all static maps.
    type.addStaticBlock(CodeBlock.builder()
      .addStatement("registerCalendars()")
      .addStatement("registerNumbers()")
      .addStatement("registerDefaultContent()")
      .addStatement("registerLanguageAliases()")
      .addStatement("registerTerritoryAliases()")
      .addStatement("registerLikelySubtags()")
      .addStatement("instance = new CLDR()").build());
    
    type.addField(instance);

    saveClass(outputDir, PACKAGE_CLDR, "CLDR", type.build());
  }
1260736
void writeReport() throws IOException {
		StringBuilder builder = new StringBuilder();
		for (DumpProcessingAction action : this.clientConfiguration
				.getActions()) {
			if (this.clientConfiguration.getReportFileName() != null) {
				builder.append(action.getActionName());
				builder.append(": ");
				if (action.isReady()) {
					builder.append(action.getReport());
				} else {
					builder.append("Action was not executed.");
				}
				builder.append(System.getProperty("line.separator"));
			} else {
				logger.info(action.getActionName() + ": " + action.getReport());
			}
		}
		if (this.clientConfiguration.getReportFileName() != null) {
			Path outputDirectory = Paths.get(
					this.clientConfiguration.getReportFileName()).getParent();
			if (outputDirectory == null) {
				outputDirectory = Paths.get(".");
			}
			DirectoryManager dm = DirectoryManagerFactory
					.createDirectoryManager(outputDirectory, false);
			OutputStream out = dm.getOutputStreamForFile(Paths
					.get(this.clientConfiguration.getReportFileName())
					.getFileName().toString());
			out.write(builder.toString().getBytes(StandardCharsets.UTF_8));
			out.close();
		}
	}