Example usage for org.apache.commons.io IOUtils toInputStream

List of usage examples for org.apache.commons.io IOUtils toInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils toInputStream.

Prototype

public static InputStream toInputStream(String input) 

Source Link

Document

Convert the specified string to an input stream, encoded as bytes using the default character encoding of the platform.

Usage

From source file:com.smartitengineering.cms.spi.impl.content.template.JythonObjectFactory.java

public JythonObjectFactory(Class<? extends T> interfaceType, String script) {
    this.interfaceType = interfaceType;
    pythonInterpreter = new PythonInterpreter();
    pythonInterpreter.exec(FileUtil.wrap(IOUtils.toInputStream(script)));
    klass = pythonInterpreter.get("rep");
}

From source file:cz.muni.fi.mir.mathmlunificator.utils.DOMBuilder.java

/**
 * Build W3C DOM representation of XML file specified by filesystem path.
 *
 * @param doc String with XML document to build DOM from.
 * @return W3C DOM representation of the XML document.
 * @throws ParserConfigurationException If a DocumentBuilder cannot be
 * created which satisfies the configuration requested.
 * @throws SAXException If any parse errors occur.
 * @throws IOException If any IO errors occur.
 *//*  w  w  w . j  a va  2s.co m*/
public static Document buildDoc(String doc) throws ParserConfigurationException, SAXException, IOException {
    return getDocumentBuilder().parse(IOUtils.toInputStream(doc));
}

From source file:com.github.thesmartenergy.mdq.entities.Vocabulary.java

@Override
public String asXML() {
    Model model = ModelFactory.createDefaultModel().read(IOUtils.toInputStream(asTurtle()), "http://ex.org/",
            "TTL");
    StringWriter sw = new StringWriter();
    model.write(sw);/*from w  ww. j ava  2  s.c  om*/
    return sw.toString();
}

From source file:com.collective.celos.ci.testing.tree.TreeStructureProcessorTest.java

@Test
public void testTreeStructureProcessor() throws IOException {
    FixDir dir1 = createDirWithSubdirsAndFile();
    InputStream inputStream2 = IOUtils.toInputStream("stream3");
    FixFile file = new FixFile(inputStream2);

    Map<String, FixFsObject> content = Maps.newHashMap();
    content.put("dir1", dir1);
    content.put("file", file);
    FixDir dir = new FixDir(content);

    TreeObjectProcessorImpl holder = new TreeObjectProcessorImpl();
    TreeObjectProcessor.process(dir, holder);

    List<Path> expectedStructure = Lists.newArrayList(Paths.get(""), Paths.get("file"), Paths.get("dir1"),
            Paths.get("dir1/file"), Paths.get("dir1/dir1"), Paths.get("dir1/dir1/file1"),
            Paths.get("dir1/dir1/file2"), Paths.get("dir1/dir2"), Paths.get("dir1/dir2/file1"),
            Paths.get("dir1/dir2/file2"));

    Collections.sort(expectedStructure);
    Collections.sort(holder.content);
    Assert.assertEquals(holder.content, expectedStructure);
}

From source file:com.collective.celos.ci.testing.fixtures.convert.JsonExpandConverterTest.java

@Test
public void testJsonExpandConverterNoConversion() throws Exception {
    JsonExpandConverter converter = new JsonExpandConverter(Sets.<String>newHashSet());
    String jsonExample = "{\"id\":\"134f50faa804d30\",\"change\":\"{\\\"daystamp\\\":\\\"20140901\\\",\\\"context\\\":\\\"none\\\"}\",\"origin\":\"dc\"}\n"
            + "{\"id\":\"134f50faa804d31\",\"change\":\"{\\\"daystamp\\\":\\\"20140902\\\",\\\"context\\\":\\\"none\\\"}\",\"origin\":\"dc\"}";

    InputStream inputStream = IOUtils.toInputStream(jsonExample);
    FixFile expanded = converter.convert(null, new FixFile(inputStream));
    String expandedStr = IOUtils.toString(expanded.getContent());

    Assert.assertEquals(jsonExample, expandedStr);
}

From source file:au.edu.usq.fascinator.harvester.feed.FeedItemMetadataPayload.java

@Override
public InputStream getInputStream() throws IOException {
    return IOUtils.toInputStream(FeedHelper.toRDFXML(feedEntry));
}

From source file:com.collective.celos.ci.testing.fixtures.convert.FixTableToJsonFileConverter.java

@Override
public FixFile convert(TestRun tr, FixTable ff) throws Exception {
    List<String> jsonStrs = Lists.newArrayList();
    for (FixTable.FixRow fr : ff.getRows()) {
        jsonStrs.add(gson.toJson(fr.getCells()));
    }// www  .  j av a 2 s  .c o  m
    return new FixFile(IOUtils.toInputStream(StringUtils.join(jsonStrs, "\n")));
}

From source file:com.allogy.mime.MimeGeneratingInputStreamTest.java

@Before
public void setUp() {
    headers = new ArrayList<Header>();
    for (int i = 0; i < 3; i++) {
        Header header = new BasicHeader(UUID.randomUUID().toString(), UUID.randomUUID().toString());
        headers.add(header);//from  w  w  w .j  a va2  s. c  om
    }

    body = UUID.randomUUID().toString();
    bodyStream = IOUtils.toInputStream(body);
}

From source file:com.sap.research.connectivity.gw.GwUtils.java

public static void createClassFileFromTemplate(String packageName, String subFolder, String templateFileName,
        String targetFileName, Map<String, String> replacements, FileManager fileManager,
        Class<?> loadingClass) {
    InputStream inputStream = null;
    OutputStream outputStream = null;
    String targetFile = subFolder + SEPARATOR + targetFileName;
    MutableFile mutableFile = fileManager.exists(targetFile) ? fileManager.updateFile(targetFile)
            : fileManager.createFile(targetFile);
    try {/* w  ww .  j  a va 2 s .  c  o m*/
        inputStream = FileUtils.getInputStream(loadingClass, templateFileName);
        outputStream = mutableFile.getOutputStream();
        String inputStreamString = IOUtils.toString(inputStream);

        for (Map.Entry<String, String> entry : replacements.entrySet()) {
            inputStreamString = inputStreamString.replace(entry.getKey(), entry.getValue());
        }
        //System.out.println(inputStreamString);
        inputStream = IOUtils.toInputStream(inputStreamString);
        IOUtils.copy(inputStream, outputStream);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } finally {
        IOUtils.closeQuietly(inputStream);
        IOUtils.closeQuietly(outputStream);
    }
}

From source file:com.allogy.couch.importers.command.BufferedCouchImporterTest.java

@Before
public void setUp() {
    targetCouchDbConnector = mock(CouchDbConnector.class);

    id = UUID.randomUUID().toString();
    dataInputStream = IOUtils.toInputStream(UUID.randomUUID().toString());

    importCommand = mock(ImportCommand.class);
    stub(importCommand.getTargetCouchDbConnector()).toReturn(targetCouchDbConnector);
    stub(importCommand.getId()).toReturn(id);
    stub(importCommand.getDataStream()).toReturn(dataInputStream);

    bufferSize = 1000;/*from   w  w w.  j  av a  2  s  . c om*/
}