Creates documents.

@param filenames array of input files
@param outputbases array of output filenames without extension
@param formats types of renderer
@throws TesseractException
510959
@Override
    public void createDocuments(String[] filenames, String[] outputbases, List<RenderedFormat> formats) throws TesseractException {
        if (filenames.length != outputbases.length) {
            throw new RuntimeException("The two arrays must match in length.");
        }

        init();
        setTessVariables();

        try {
            for (int i = 0; i < filenames.length; i++) {
                File inputFile = new File(filenames[i]);
                File imageFile = null;

                try {
                    // if PDF, convert to multi-page TIFF
                    imageFile = ImageIOHelper.getImageFile(inputFile);

                    TessResultRenderer renderer = createRenderers(outputbases[i], formats);
                    createDocuments(imageFile.getPath(), renderer);
                    api.TessDeleteResultRenderer(renderer);
                } catch (Exception e) {
                    // skip the problematic image file
                    logger.warn(e.getMessage(), e);
                } finally {
                    // delete temporary TIFF image for PDF
                    if (imageFile != null && imageFile.exists() && imageFile != inputFile && imageFile.getName().startsWith("multipage") && imageFile.getName().endsWith(ImageIOHelper.TIFF_EXT)) {
                        imageFile.delete();
                    }
                }
            }
        } finally {
            dispose();
        }
    }
1194363
void generate( Application application, Collection<TemplateEntry> templates ) {

		try {
			synchronized( this.generationLock ) {
				TemplateUtils.generate( application, this.outputDIR, templates, this.logger );
			}

		} catch( IOException e ) {
			this.logger.warning( "An error occurred while generating files from templates for application " + application );
			Utils.logException( this.logger, e );

		} catch( Throwable e ) {
			this.logger.warning( "An unexpected error occurred while generating files from templates for application " + application );
			Utils.logException( this.logger, new UndeclaredThrowableException( e ));
		}
	}
1022876
def run_tesseract(input_filename, output_filename_base, lang=None, boxes=False):
    '''
    

    '''

    command = [tesseract_cmd, input_filename, output_filename_base]

    if lang is not None:
        command += ['-l', lang]

    if boxes:
        command += ['batch.nochop', 'makebox']

    proc = subprocess.Popen(command,
                            stderr=subprocess.PIPE)
    return (proc.wait(), proc.stderr.read())
513385
function(filename, template, outputInInput) {
    var basename;
    var glob;

    template = Array.isArray(template) ? filename : template;
    glob = isGlob(template);
    if (outputInInput) {
      basename = _toArray(filename.split('.').pop()) ;
    } else if (glob) {
      basename = filename.slice(glob.length, filename.length).split('.');
      basename.pop();
    } else {
      basename = filename.split('/').pop().split('.');
      basename.pop();
    }
    return basename.join('.');
  }
704958
public static Workbook createWorkbook(FileFormat format, OutputStream os)
        throws IOException
    {
        return createWorkbook(format, os, null);
    }
822424
private void createUtilityFiles() throws Exception {
        // create the right files in the right places
        // cats/<name>
        File ds = new File(mapsetPath + File.separator + GrassLegacyConstans.CATS + File.separator + name);
        OutputStreamWriter catsWriter = new OutputStreamWriter(new FileOutputStream(ds));
        catsWriter.write("# xyz categories\n#\n#\n 0.00 0.00 0.00 0.00");
        catsWriter.close();

        // cell/<name>
        ds = new File(mapsetPath + File.separator + GrassLegacyConstans.CELL + File.separator + name);
        OutputStreamWriter cellWriter = new OutputStreamWriter(new FileOutputStream(ds));
        cellWriter.write("");
        cellWriter.close();

        // cell_misc/<name>/<files>
        // the directory <name> in cell_misc has already been created in
        // writeMapInActiveRegion (or extended) of the Class Mapset (or
        // extended)

        // f_format
        ds = new File(mapsetPath + File.separator + GrassLegacyConstans.CELL_MISC + File.separator + name + File.separator
                + GrassLegacyConstans.CELLMISC_FORMAT);
        OutputStreamWriter cell_miscFormatWriter = new OutputStreamWriter(new FileOutputStream(ds));
        if (outputToDiskType * 4 == 8) {
            cell_miscFormatWriter.write("type: double\nbyte_order: xdr\nlzw_compression_bits: -1");
        } else {
            cell_miscFormatWriter.write("type: float\nbyte_order: xdr\nlzw_compression_bits: -1");
        }

        cell_miscFormatWriter.close();

        // f_quant
        ds = new File(mapsetPath + File.separator + GrassLegacyConstans.CELL_MISC + File.separator + name + File.separator
                + GrassLegacyConstans.CELLMISC_QUANT);
        OutputStreamWriter cell_miscQantWriter = new OutputStreamWriter(new FileOutputStream(ds));
        cell_miscQantWriter.write("round");
        cell_miscQantWriter.close();

        // f_range
        ds = new File(mapsetPath + File.separator + GrassLegacyConstans.CELL_MISC + File.separator + name + File.separator
                + GrassLegacyConstans.CELLMISC_RANGE);
        OutputStream cell_miscRangeStream = new FileOutputStream(ds);
        // if (logger.isDebugEnabled())
        // logger.debug("RRRRRRRRRRRRRANGES: " + range[0] + "/" + range[1]);
        cell_miscRangeStream.write(FileUtilities.double2bytearray(range[0]));
        cell_miscRangeStream.write(FileUtilities.double2bytearray(range[1]));
        cell_miscRangeStream.close();

        // write the file cellhd
        /*
         * this won't work since the default window lost the proj information somewhere. When it is
         * set at the begin, it is there. This is a problem, since grass 6.0 complains about wrong
         * proj!!! It doesn't show rasters. createCellhd(GrassEnvironmentManager.getInstance()
         * .getCurrentSessionGrassEnvironment().getLocation().getDefaultWindow() .getProj(),
         * GrassEnvironmentManager.getInstance()
         * .getCurrentSessionGrassEnvironment().getLocation().getDefaultWindow() .getZone(),
         * dataWindow.getNorth(), dataWindow.getSouth(), dataWindow .getEast(),
         * dataWindow.getWest(), dataWindow.getCols(), dataWindow .getRows(),
         * dataWindow.getNSResolution(), dataWindow.getWEResolution(), -1, 1);
         */

        /*
         * need to reread the wind file to get the proj and zone (GRASS will not work if the cellhd
         * is not equal to the WIND proj)
         */
        Window tmp = new Window(locationPath + File.separator + GrassLegacyConstans.PERMANENT_MAPSET + File.separator
                + GrassLegacyConstans.WIND);
        createCellhd(tmp.getProj(), tmp.getZone(), dataWindow.getNorth(), dataWindow.getSouth(), dataWindow.getEast(),
                dataWindow.getWest(), dataWindow.getCols(), dataWindow.getRows(), dataWindow.getNSResolution(),
                dataWindow.getWEResolution(), -1, 1);

        // hist/<name>
        ds = new File(mapsetPath + File.separator + GrassLegacyConstans.HIST + File.separator + name);
        OutputStreamWriter windFile = new OutputStreamWriter(new FileOutputStream(ds));
        Date date = new Date();
        windFile.write(date + "\n");
        windFile.write(name + "\n");
        windFile.write(mapsetPath + "\n");
        windFile.write("generic user\n");
        windFile.write("DCELL\n");
        windFile.write("\n\nCreated by JGrass\n");
        windFile.write(historyComment + "\n");
        windFile.close();
        // now all the files have been created
    }
1305545
public void generateReport(List<XmlSuite> xmlSuites,
                               List<ISuite> suites,
                               String outputDirectoryName)
    {
        removeEmptyDirectories(new File(outputDirectoryName));
        
        boolean useFrames = System.getProperty(FRAMES_PROPERTY, "true").equals("true");
        boolean onlyFailures = System.getProperty(ONLY_FAILURES_PROPERTY, "false").equals("true");

        File outputDirectory = new File(outputDirectoryName, REPORT_DIRECTORY);
        outputDirectory.mkdirs();

        try
        {
            if (useFrames)
            {
                createFrameset(outputDirectory);
            }
            createOverview(suites, outputDirectory, !useFrames, onlyFailures);
            createSuiteList(suites, outputDirectory, onlyFailures);
            createGroups(suites, outputDirectory);
            createResults(suites, outputDirectory, onlyFailures);
            createLog(outputDirectory, onlyFailures);
            copyResources(outputDirectory);
        }
        catch (Exception ex)
        {
            throw new ReportNGException("Failed generating HTML report.", ex);
        }
    }
618540
public void writeDocument(String filename, ProvFormat format, Document document) {
        Namespace.withThreadNamespace(document.getNamespace());
        try {
            logger.debug("writing " + format);
            logger.debug("writing " + filename);
            setNamespaces(document);
            switch (format) {
            case PROVN: {
                u.writeDocument(document, filename, pFactory);
                break;
            }
            case XML: {
                ProvSerialiser serial = ProvSerialiser
                        .getThreadProvSerialiser();
                logger.debug("namespaces " + document.getNamespace());
                serial.serialiseDocument(new File(filename), document, true);
                break;
            }
            case TURTLE: {
                new org.openprovenance.prov.rdf.Utility(pFactory, onto)
                        .dumpRDF(document, RDFFormat.TURTLE, filename);
                break;
            }
            case RDFXML: {
                new org.openprovenance.prov.rdf.Utility(pFactory, onto)
                        .dumpRDF(document, RDFFormat.RDFXML, filename);
                break;
            }
            case TRIG: {
                new org.openprovenance.prov.rdf.Utility(pFactory, onto)
                        .dumpRDF(document, RDFFormat.TRIG, filename);
                break;
            }
            case JSON: {
                new org.openprovenance.prov.json.Converter(pFactory)
                        .writeDocument(document, filename);
                break;
            }
            case DOT: {
                String configFile = null; // TODO: get it as option
                ProvToDot toDot = (configFile == null) ? new ProvToDot(
                        ProvToDot.Config.ROLE_NO_LABEL) : new ProvToDot(
                        configFile);
                toDot.setLayout(layout);
                toDot.convert(document, filename, title);
                break;
            }
            case PDF:
            case JPEG:
            case PNG:
            case SVG: {
                String configFile = null; // give it as option
                File tmp = File.createTempFile("viz-", ".dot");

                String dotFileOut = tmp.getAbsolutePath(); // give it as option,
                                                           // if not available
                                                           // create tmp file
                ProvToDot toDot;
                if (configFile != null) {
                    toDot = new ProvToDot(configFile);
                } else {
                    toDot = new ProvToDot(ProvToDot.Config.ROLE_NO_LABEL);
                }
                toDot.setLayout(layout);
                toDot.convert(document, dotFileOut, filename, extensionMap.get(format), title);
                tmp.delete();
                break;
            }

            default:
                break;
            }
        } catch (JAXBException e) {
            if (verbose != null)
                e.printStackTrace();
            throw new InteropException(e);

        } catch (IOException e) {
            if (verbose != null)
                e.printStackTrace();
            throw new InteropException(e);
        }

    }
474655
public void setOutputChannels(java.util.Collection<OutputChannelMapping> outputChannels) {
        if (outputChannels == null) {
            this.outputChannels = null;
            return;
        }

        this.outputChannels = new java.util.ArrayList<OutputChannelMapping>(outputChannels);
    }
1053909
private void processFiles(File[] files) {
        phaseOutput(format("=== %s ===", getApplicationName()));
        phaseOutput(format("Compiling %d BEL Document(s)", files.length));

        boolean pedantic = withPedantic();
        boolean verbose = withVerbose();

        int validated = 0;

        for (int i = 1; i <= files.length; i++) {
            File file = files[i - 1];

            if (verbose) {
                phaseOutput("Compiling " + i + " of " + files.length
                        + " BEL Document(s)");
            }

            // validate document
            Document document = stage1(file);
            if (document == null) {
                if (pedantic) {
                    bail(VALIDATION_FAILURE);
                }
                continue;
            }
            validated++;

            // run stages 2 - 7
            runCommonStages(pedantic, document);
        }

        if (validated == 0) {
            bail(NO_VALID_DOCUMENTS);
        }
    }
136036
@Programmatic
    public DocumentTemplate createBlob(
            final DocumentType type,
            final LocalDate date,
            final String atPath,
            final String fileSuffix,
            final boolean previewOnly,
            final Blob blob,
            final RenderingStrategy contentRenderingStrategy,
            final String subjectText,
            final RenderingStrategy subjectRenderingStrategy) {
        final DocumentTemplate document =
                new DocumentTemplate(
                        type, date, atPath,
                        fileSuffix, previewOnly, blob,
                        contentRenderingStrategy,
                        subjectText, subjectRenderingStrategy);
        repositoryService.persistAndFlush(document);
        return document;
    }
709124
public void render(Map<String, Object> content) throws Exception {
        String docType = (String) content.get(Crawler.Attributes.TYPE);
        String outputFilename = config.getDestinationFolder().getPath() + File.separatorChar + content.get(Attributes.URI);
        if (outputFilename.lastIndexOf('.') > outputFilename.lastIndexOf(File.separatorChar)) {
            outputFilename = outputFilename.substring(0, outputFilename.lastIndexOf('.'));
        }

        // delete existing versions if they exist in case status has changed either way
        String outputExtension = config.getOutputExtensionByDocType(docType);
        File draftFile = new File(outputFilename, config.getDraftSuffix() + outputExtension);
        if (draftFile.exists()) {
            draftFile.delete();
        }

        File publishedFile = new File(outputFilename + outputExtension);
        if (publishedFile.exists()) {
            publishedFile.delete();
        }

        if (content.get(Crawler.Attributes.STATUS).equals(Crawler.Attributes.Status.DRAFT)) {
            outputFilename = outputFilename + config.getDraftSuffix();
        }

        File outputFile = new File(outputFilename + outputExtension);
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("content", content);
        model.put("renderer", renderingEngine);

        try {
            try (Writer out = createWriter(outputFile)) {
                renderingEngine.renderDocument(model, findTemplateName(docType), out);
            }
            LOGGER.info("Rendering [{}]... done!", outputFile);
        } catch (Exception e) {
            LOGGER.error("Rendering [{}]... failed!", outputFile, e);
            throw new Exception("Failed to render file " + outputFile.getAbsolutePath() + ". Cause: " + e.getMessage(), e);
        }
    }
519209
function generateFormatterExamples(formatterInfo, prereleaseVersion) {
    const output = ejs.render(cat("./templates/formatter-examples.md.ejs"), formatterInfo);
    let filename = "../eslint.github.io/docs/user-guide/formatters/index.md",
        htmlFilename = "../eslint.github.io/docs/user-guide/formatters/html-formatter-example.html";

    if (prereleaseVersion) {
        filename = filename.replace("/docs", `/docs/${prereleaseVersion}`);
        htmlFilename = htmlFilename.replace("/docs", `/docs/${prereleaseVersion}`);
        if (!test("-d", path.dirname(filename))) {
            mkdir(path.dirname(filename));
        }
    }

    output.to(filename);
    formatterInfo.formatterResults.html.result.to(htmlFilename);
}
749358
public void writeDocument(String filename, Document document) {
            ProvFormat format = getTypeForFile(filename);
            if (format == null) {
                System.err.println("Unknown output file format: " + filename);
                return;
            }
        writeDocument(filename, format, document);
    }
997635
private void write(final Document document) throws IOException, TransformerException {
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
		Transformer transformer = transformerFactory.newTransformer();
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
		transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
		transformer
				.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://cobertura.sourceforge.net/xml/coverage-04.dtd");
		try (BufferedWriter bufferedWriter = Files.newBufferedWriter(this.reportPath)) {
			transformer.transform(new DOMSource(document), new StreamResult(bufferedWriter));
		}
	}
407435
public void writeGridInPmeshFormat(String outPutFileName) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(outPutFileName + ".pmesh"));
        int numberOfGridPoints = grid.length * grid[0].length * grid[0][0].length;
        writer.write(numberOfGridPoints + "\n");
        for (int z = 0; z < grid[0][0].length; z++) {
            for (int y = 0; y < grid[0].length; y++) {
                for (int x = 0; x < grid.length; x++) {
                    Point3d coords = getCoordinatesFromGridPoint(new Point3d(x, y, z));
                    writer.write(coords.x + "\t" + coords.y + "\t" + coords.z + "\n");
                }
            }
        }
        writer.close();
    }
268967
protected void generateReadme(String basename) {
		final Object content = getReadmeFileContent(basename);
		if (content != null) {
			final String textualContent = content.toString();
			if (!Strings.isEmpty(textualContent)) {
				final byte[] bytes = textualContent.getBytes();
				for (final String output : getOutputs()) {
					final File directory = new File(output).getAbsoluteFile();
					try {
						directory.mkdirs();
						final File outputFile = new File(directory, README_BASENAME);
						Files.write(Paths.get(outputFile.getAbsolutePath()), bytes);
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
			}
		}
	}