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.telefonica.euro_iaas.paasmanager.dao.sdc.impl.ProductReleaseSdcDaoImplTest.java

/**
 * Tests the findAllProducts functionality
 * //from   w ww  . ja va2s.com
 * @throws SdcException
 */
@Test
public void testFindAllProducts() throws SdcException {
    // given

    String jsonProducts = "{\"product\":[{\"name\":\"tomcat\",\"description\":\"tomcat J2EE container\",\"attributes\":{\"key\":\"clave\",\"value\":\"valor\"}},{\"name\":\"nodejs\",\"description\":\"nodejs\"},{\"name\":\"mysql\",\"description\":\"mysql\"},{\"name\":\"git\",\"description\":\"git\"},{\"name\":\"mongodbshard\",\"description\":\"mongodbshard\"},{\"name\":\"mongos\",\"description\":\"mongos\"},{\"name\":\"mongodbconfig\",\"description\":\"mongodbconfig\"},{\"name\":\"contextbroker\",\"description\":\"contextbroker\"},{\"name\":\"postgresql\",\"description\":\"db manager\",\"attributes\":[{\"key\":\"username\",\"value\":\"postgres\",\"description\":\"The administrator usename\"},{\"key\":\"password\",\"value\":\"postgres\",\"description\":\"The administrator password\"}]},{\"name\":\"haproxy\",\"description\":\"balancer\",\"attributes\":[{\"key\":\"key1\",\"value\":\"value1\",\"description\":\"keyvaluedesc1\"},{\"key\":\"key2\",\"value\":\"value2\",\"description\":\"keyvaluedesc2\"},{\"key\":\"sdccoregroupid\",\"value\":\"app_server_role\",\"description\":\"idcoregroup\"}]},{\"name\":\"test\",\"description\":\"test\",\"attributes\":{\"key\":\"clave\",\"value\":\"valor\"}},{\"name\":\"mediawiki\",\"description\":\"MediaWiki Product\",\"attributes\":[{\"key\":\"wikiname\",\"value\":\"Wiki to be shown\",\"description\":\"The name of the wiki\"},{\"key\":\"path\",\"value\":\"/demo\",\"description\":\"The url context to be displayed\"}]}]}";
    // String productReleasesList =
    // "{\"productRelease\":{\"releaseNotes\":\"Tomcat server 6\",\"version\":\"6\",\"product\":{\"name\":\"tomcat\",\"description\":\"tomcat J2EE container\",\"attributes\":{\"key\":\"clave\",\"value\":\"valor\"}},\"supportedOOSS\":[{\"description\":\"Ubuntu 10.04\",\"name\":\"Ubuntu\",\"osType\":\"94\",\"version\":\"10.04\"},{\"description\":\"Debian 5\",\"name\":\"Debian\",\"osType\":\"95\",\"version\":\"5\"},{\"description\":\"Centos 2.9\",\"name\":\"Centos\",\"osType\":\"76\",\"version\":\"2.9\"}]}}\"";
    InputStream inputStream = IOUtils.toInputStream(jsonProducts);

    when(builder.get(InputStream.class)).thenReturn(inputStream);

    List<String> products = productReleaseSdcDaoImpl.findAllProducts("token", "tenant");

    // then
    assertNotNull(products);

}

From source file:gov.nasa.ensemble.resources.TestProjectProperties.java

@Test
public void move() throws CoreException, InterruptedException {
    final String key = "key", val1 = "val1", val2 = "val2";
    final TestListener listener = new TestListener();
    projProps(file).set(key, val1);

    while (!ProjectProperties.propFile(file, key).exists())
        Thread.sleep(50);/* www . ja v a  2 s.c  om*/

    projProps(file).addListener(listener);
    final IFile moved = proj.getFile("moved");
    file.move(moved.getFullPath(), true, null);

    file.create(IOUtils.toInputStream(""), true, null);
    assertTrue("After moving file, new file created in original's place still had old project properties",
            projProps(file).get(key).isNone());
    assertFalse(listener.changed);
    assertTrue("Moved file did not retain its project properties", projProps(moved).get(key).isSome());
    assertEquals(val1, projProps(moved).get(key).some());
    projProps(moved).set(key, val2);
    assertFalse(listener.changed);
    assertTrue(projProps(file).get(key).isNone());
}

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

@Test(expected = IOException.class)
public void getContentInputStream_should_throw_exception_if_stream_ends_before_header_part_ends()
        throws IOException {
    String header = "header: value";

    mimeInputStream = IOUtils.toInputStream(header);

    createObjectUnderTest().getContentInputStream();
}

From source file:com.msopentech.odatajclient.engine.it.MediaEntityTestITCase.java

@Test
public void createMediaEntityAsAtom() throws Exception {
    createMediaEntity(ODataPubFormat.ATOM, IOUtils.toInputStream("buffered stream sample"));
}

From source file:eu.learnpad.core.rest.XWikiRestUtils.java

public boolean createEmptyPage(String wikiName, String spaceName, String pageName) {
    String emptyPageXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><page xmlns=\"http://www.xwiki.org\"><hidden>true</hidden><content/></page>";
    return putPage(wikiName, spaceName, pageName, IOUtils.toInputStream(emptyPageXML));
}

From source file:com.pieframework.model.repository.ModelStore.java

public static Model evaluateTemplateExpressions(Model model) throws SimpleSerializerException, IOException {

    System system = model.getSystem();
    String systemTemplate = evalAsTemplate(system);
    System newSystem = DefaultSerializer.read(System.class, IOUtils.toInputStream(systemTemplate));

    // Resources resources = new Resources();
    // resources.setResources(model.getResources());
    // String resourcesTemplate = evalAsTemplate(resources);
    // Resources newResources = DefaultSerializer.read(Resources.class,
    // IOUtils.toInputStream(resourcesTemplate));

    // Operations ops = new Operations();
    // ops.setOperations(model.getOperations());
    // String opsTemplate = evalAsTemplate(ops);
    // ops = DefaultSerializer.read(Operations.class, IOUtils
    // .toInputStream(opsTemplate));

    Repositories repos = new Repositories();
    repos.setRepositories(model.getRepositories());
    String repoTemplate = evalAsTemplate(repos);
    repos = DefaultSerializer.read(Repositories.class, IOUtils.toInputStream(repoTemplate));

    // TODO should probably clone model
    Model returnModel = new Model().withSystem(newSystem).withModelDirectory(model.getModelDirectory())
            .withRepositories(repos).withConfiguration(model.getConfiguration())
            .withRequest(model.getRequest());

    return returnModel;
}

From source file:com.github.jarlakxen.embedphantomjs.executor.PhantomJSConsoleExecutor.java

public ListenableFuture<String> execute(final String scriptSource, String... endLines)
        throws UnexpectedProcessEndException {
    return this.execute(IOUtils.toInputStream(scriptSource), asList(endLines));
}

From source file:com.msopentech.odatajclient.engine.it.MediaEntityTestITCase.java

@Test
public void createMediaEntityAsJson() throws Exception {
    createMediaEntity(ODataPubFormat.JSON, IOUtils.toInputStream("buffered stream sample"));
}

From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java

/**
 * {@inheritDoc }/*  w ww .  j a  v a  2  s  .  c  o m*/
 */
@Override
protected NavigationLinks retrieveNavigationInfo(final String entitySetName, final InputStream is)
        throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
    IOUtils.closeQuietly(is);

    final NavigationLinks links = new NavigationLinks();

    final Iterator<Map.Entry<String, JsonNode>> fieldIter = srcNode.fields();

    while (fieldIter.hasNext()) {
        final Map.Entry<String, JsonNode> field = fieldIter.next();
        if (field.getKey().endsWith(JSON_NAVIGATION_BIND_SUFFIX)) {
            final String title = field.getKey().substring(0, field.getKey().indexOf('@'));
            final List<String> hrefs = new ArrayList<String>();
            if (field.getValue().isArray()) {
                for (JsonNode href : ((ArrayNode) field.getValue())) {
                    final String uri = href.asText();
                    hrefs.add(uri.substring(uri.lastIndexOf('/') + 1));
                }
            } else {
                final String uri = field.getValue().asText();
                hrefs.add(uri.substring(uri.lastIndexOf('/') + 1));
            }

            links.addLinks(title, hrefs);
        } else if (Commons.linkInfo.get(version).exists(entitySetName, field.getKey())) {
            links.addInlines(field.getKey(), IOUtils.toInputStream(field.getValue().toString()));
        }
    }

    return links;
}

From source file:com.github.restdriver.clientdriver.unit.ClientDriverResponseTest.java

@Test
public void creatingResponseWithInputStreamReturnsCorrectValueWhenFetchingContentAsString() {
    ClientDriverResponse response = new ClientDriverResponse(IOUtils.toInputStream("some text"),
            "application/octet-stream");

    assertThat(response.getContent(), is("some text"));
}