Example usage for org.apache.commons.io FileUtils openInputStream

List of usage examples for org.apache.commons.io FileUtils openInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils openInputStream.

Prototype

public static FileInputStream openInputStream(File file) throws IOException 

Source Link

Document

Opens a FileInputStream for the specified file, providing better error messages than simply calling new FileInputStream(file).

Usage

From source file:io.dockstore.client.cli.nested.AbstractEntryClient.java

private String convertYamlToJson(String yamlRun, String jsonRun) throws IOException {
    // if we have a yaml parameter file, convert it into a json
    if (yamlRun != null) {
        final File tempFile = File.createTempFile("temp", "json");
        Yaml yaml = new Yaml();
        final FileInputStream fileInputStream = FileUtils.openInputStream(new File(yamlRun));
        Map<String, Object> map = (Map<String, Object>) yaml.load(fileInputStream);
        JSONObject jsonObject = new JSONObject(map);
        final String jsonContent = jsonObject.toString();
        FileUtils.write(tempFile, jsonContent, StandardCharsets.UTF_8);
        jsonRun = tempFile.getAbsolutePath();
    }//from ww w. j a  v  a  2 s  . c  om
    return jsonRun;
}

From source file:net.technicpack.launcher.ui.components.discover.DiscoverInfoPanel.java

public Document getDiscoverDocumentFromLocalCache(File localCache) {
    try {//  ww  w  .j av a 2s .  c om
        return XMLResource.load(FileUtils.openInputStream(localCache)).getDocument();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return null;
}

From source file:net.technicpack.ui.lang.ResourceLoader.java

public Font getFontByName(String fontName) {
    Font font;// ww w . ja  v a2  s.  c  o m

    if (fontCache.containsKey(fontName))
        return fontCache.get(fontName);

    if (launcherAssets == null)
        return fallbackFont;

    InputStream fontStream = null;
    try {
        String fullName = getString(fontName);
        fontStream = FileUtils.openInputStream(new File(launcherAssets, fullName));

        if (fontStream == null)
            return fallbackFont;

        font = Font.createFont(Font.TRUETYPE_FONT, fontStream);
        GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
        genv.registerFont(font);
    } catch (Exception e) {
        e.printStackTrace();
        // Fallback
        return fallbackFont;
    } finally {
        if (fontStream != null)
            IOUtils.closeQuietly(fontStream);
    }
    fontCache.put(fontName, font);

    if (font == null)
        return fallbackFont;

    return font;
}

From source file:nl.knaw.huc.di.tag.tagml.importer.ImportDataTAGMLTest.java

private InputStream getInputStream(String basename) throws IOException {
    return FileUtils.openInputStream(new File("data/tagml/" + basename + ".tagml"));
}

From source file:nl.knaw.huygens.alexandria.dropwizard.cli.commands.CommitCommand.java

private void processTAGMLFile(CLIContext context, TAGStore store, String fileName, String docName) {
    System.out.printf("Parsing %s to document %s...%n", fileName, docName);

    store.runInTransaction(Unchecked.runnable(() -> {
        TAGMLImporter tagmlImporter = new TAGMLImporter(store);
        File file = workFilePath(fileName).toFile();
        FileInputStream fileInputStream = FileUtils.openInputStream(file);
        TAGDocument document = tagmlImporter.importTAGML(fileInputStream);
        NamedDocumentService service = new NamedDocumentService(store);
        service.registerDocument(document, docName);
        DocumentInfo newDocumentInfo = new DocumentInfo().setDocumentName(docName).setSourceFile(fileName)
                .setDbId(document.getDbId());
        context.getDocumentInfo().put(docName, newDocumentInfo);
    }));/*ww w .ja v  a 2 s.  co  m*/
}

From source file:nl.knaw.huygens.alexandria.exporter.LaTexExporterInMemoryTest.java

private void processLMNLFile(String basename) throws IOException, LMNLSyntaxError {
    InputStream input = FileUtils.openInputStream(new File("data/lmnl/" + basename + ".lmnl"));
    Document document = new LMNLImporterInMemory().importLMNL(input);
    LaTeXExporterInMemory exporter = new LaTeXExporterInMemory(document);
    String outDir = "out/";

    String laTeX = exporter.exportDocument();
    assertThat(laTeX).isNotBlank();/*ww w .j a  va  2s  .  co  m*/
    LOG.info("document=\n{}", laTeX);
    FileUtils.writeStringToFile(new File(outDir + basename + ".tex"), laTeX, "UTF-8");

    String overlap = exporter.exportGradient();
    assertThat(overlap).isNotBlank();
    LOG.info("overlap=\n{}", overlap);
    FileUtils.writeStringToFile(new File(outDir + basename + "-gradient.tex"), overlap, "UTF-8");

    String coloredText = exporter.exportMarkupOverlap();
    assertThat(coloredText).isNotBlank();
    FileUtils.writeStringToFile(new File(outDir + basename + "-colored-text.tex"), coloredText, "UTF-8");

    String matrix = exporter.exportMatrix();
    assertThat(matrix).isNotBlank();
    LOG.info("matrix=\n{}", laTeX);
    FileUtils.writeStringToFile(new File(outDir + basename + "-matrix.tex"), matrix, "UTF-8");

    String kdTree = exporter.exportKdTree();
    assertThat(kdTree).isNotBlank();
    LOG.info("k-d tree=\n{}", kdTree);
    FileUtils.writeStringToFile(new File(outDir + basename + "-kdtree.tex"), kdTree, "UTF-8");
}

From source file:nl.knaw.huygens.alexandria.exporter.LaTexExporterInMemoryTest.java

private String laTeXFromLMNLFile(String pathname) throws IOException, LMNLSyntaxError {
    InputStream input = FileUtils.openInputStream(new File(pathname));
    Document document = new LMNLImporterInMemory().importLMNL(input);
    return toLaTeX(document);
}

From source file:nl.knaw.huygens.alexandria.lmnl.importer.ImportDataLMNLInMemoryTest.java

private InputStream getInputStream(String basename) throws IOException {
    return FileUtils.openInputStream(new File("data/lmnl/" + basename + ".lmnl"));
}

From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporterInMemoryTest.java

@Test
public void testLMNL1kings12() throws IOException, LMNLSyntaxError {
    String pathname = "data/lmnl/1kings12.lmnl";
    InputStream input = FileUtils.openInputStream(new File(pathname));
    Document actual = new LMNLImporterInMemory().importLMNL(input);
    LOG.info("document={}", actual);

    logLMNL(actual);// w ww  .  j  a v a2s  . c  o  m

    Limen actualLimen = actual.value();
    List<Markup> actualMarkupList = actualLimen.markupList;

    Markup excerpt = actualMarkupList.get(0);
    assertThat(excerpt.getTag()).isEqualTo("excerpt");

    List<Annotation> annotations = excerpt.getAnnotations();
    assertThat(annotations).hasSize(1); // just the soutce annotation;

    Annotation source = simpleAnnotation("source");
    Annotation book = simpleAnnotation("book", "1 Kings");
    source.addAnnotation(book);
    Annotation chapter = simpleAnnotation("chapter", "12");
    source.addAnnotation(chapter);
    String actualSourceLMNL = lmnlExporterInMemory.toLMNL(annotations.get(0)).toString();
    String expectedSourceLMNL = lmnlExporterInMemory.toLMNL(source).toString();
    assertThat(actualSourceLMNL).isEqualTo(expectedSourceLMNL);

    Markup q1 = actualMarkupList.get(2);
    assertThat(q1.getTag()).isEqualTo("q"); // first q
    assertThat(q1.textNodes).hasSize(2); // has 2 textnodes

    Markup q2 = actualMarkupList.get(3);
    assertThat(q2.getTag()).isEqualTo("q"); // second q, nested in first
    assertThat(q2.textNodes).hasSize(1); // has 1 textnode

    // compareLMNL(pathname, actual);
    logKdTree(actual);

    List<IndexPoint> expectedIndexPoints = new ArrayList<>();
    expectedIndexPoints.add(new IndexPoint(0, 0));
    // assertThat(indexPoints).containsExactlyElementsOf(expectedIndexPoints);
}

From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporterInMemoryTest.java

@Test
public void testLMNLOzymandias() throws IOException, LMNLSyntaxError {
    String pathname = "data/lmnl/ozymandias-voices-wap.lmnl";
    InputStream input = FileUtils.openInputStream(new File(pathname));
    Document actual = new LMNLImporterInMemory().importLMNL(input);
    LOG.info("document={}", actual);
    logLMNL(actual);//from   w  w  w  . ja va2 s . c om
    assertThat(actual.value().hasTextNodes()).isTrue();
    String lmnl = lmnlExporterInMemory.toLMNL(actual);
    assertThat(lmnl).startsWith("[sonneteer [id}ozymandias{] [encoding [resp}ebeshero{] [resp}wap{]]}"); // annotations from sonneteer endtag moved to start tag
    assertThat(lmnl).contains("[meta [author}Percy Bysshe Shelley{] [title}Ozymandias{]]"); // anonymous markup
    // compareLMNL(pathname, actual);

    logKdTree(actual);

    List<IndexPoint> expectedIndexPoints = new ArrayList<>();
    expectedIndexPoints.add(new IndexPoint(0, 0));
    // assertThat(indexPoints).containsExactlyElementsOf(expectedIndexPoints);
}