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, String encoding) throws IOException 

Source Link

Document

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

Usage

From source file:mitm.common.security.ca.CSVRequestConverterTest.java

@Test(expected = RequestConverterException.class)
public void testDuplicateColumn() throws Exception {
    String input = "e, cn, cn\r\ntest1@example.com,aaa";

    CSVRequestConverter converter = new CSVRequestConverter();

    converter.convertCSV(IOUtils.toInputStream(input, CharacterEncoding.US_ASCII));
}

From source file:mitm.application.djigzo.relay.RelayHandler.java

private RelayInfo getRelayInfo() throws IOException, MessagingException, RelayException {
    Object content = metaPart.getContent();

    if (!(content instanceof String)) {
        throw new RelayException(RelayStep.INVALID, META_INFO_IS_NOT_XML);
    }/*from  ww w  .  ja  v  a 2s.  c om*/

    String xml = (String) content;

    try {
        return RelayInfoFactory.unmarshall(IOUtils.toInputStream(xml, "UTF-8"));
    } catch (JAXBException e) {
        throw new RelayException(RelayStep.INVALID, META_XML_IS_INVALID);
    }
}

From source file:ddf.catalog.test.TestCatalog.java

private String getMetacardIdFromCswInsertResponse(Response response)
        throws IOException, XPathExpressionException {
    XPath xPath = XPathFactory.newInstance().newXPath();
    String idPath = "//*[local-name()='identifier']/text()";
    InputSource xml = new InputSource(
            IOUtils.toInputStream(response.getBody().asString(), StandardCharsets.UTF_8.name()));
    return xPath.compile(idPath).evaluate(xml);
}

From source file:de.shadowhunt.subversion.internal.AbstractRepositoryCombinedOperationsIT.java

@Test
public void test02_OverrideFile() throws Exception {
    final String content = "test";
    final Resource resource = prefix.append(Resource.create("override.txt"));

    final Transaction transaction = repository.createTransaction();
    try {/*from  ww  w. j  av  a 2 s.co  m*/
        repository.add(transaction, resource, true,
                IOUtils.toInputStream("something else", AbstractHelper.UTF8));
        repository.add(transaction, resource, true, IOUtils.toInputStream(content, AbstractHelper.UTF8));
        repository.commit(transaction, "add " + resource);
    } finally {
        repository.rollbackIfNotCommitted(transaction);
    }

    final InputStream expected = IOUtils.toInputStream(content, AbstractHelper.UTF8);
    final InputStream actual = repository.download(resource, Revision.HEAD);
    AbstractRepositoryDownloadIT.assertEquals("content must match", expected, actual);
}

From source file:com.elsevier.spark_xml_utils.xslt.XSLTProcessor.java

/**
 * Transform the content.//from   w  w w . j av  a2  s  . co  m
 * 
 * @param content the xml to be transformed
 * @param stylesheetParams HashMap of stylesheet params
 * @return transformed content
 * @throws XSLTException
 */
public String transform(String content, HashMap<String, String> stylesheetParams) throws XSLTException {

    try {

        // Create streamsource for the content
        StreamSource contentSource = new StreamSource(IOUtils.toInputStream(content, CharEncoding.UTF_8));

        // Apply transformation
        return transform(contentSource, stylesheetParams);

    } catch (IOException e) {

        log.error("Problems transforming the content. " + e.getMessage(), e);
        throw new XSLTException(e.getMessage());

    }

}

From source file:mitm.common.security.ca.CSVRequestConverterTest.java

@Test(expected = RequestConverterException.class)
public void testMissingValues() throws Exception {
    String input = "e, cn, fn\r\ntest1@example.com,aaa";

    CSVRequestConverter converter = new CSVRequestConverter();

    converter.convertCSV(IOUtils.toInputStream(input, CharacterEncoding.US_ASCII));
}

From source file:ch.entwine.weblounge.common.impl.content.page.LazyPageImpl.java

/**
 * Loads the page preview only.//  w w  w. j  ava2  s.c o m
 */
protected void loadPagePreview() {
    // If no separate preview data was given, then we need to load the whole
    // thing instead.
    if (previewXml == null) {
        loadPageBody();
        previewComposer = new ComposerImpl(PagePreviewReader.PREVIEW_COMPOSER_NAME, page.getPreview());
        return;
    }

    try {
        PagePreviewReader reader = new PagePreviewReader();
        previewComposer = reader.read(IOUtils.toInputStream(previewXml, "utf-8"), uri);
        previewXml = null;
    } catch (Throwable e) {
        logger.error("Failed to lazy-load preview of {}", uri);
        throw new IllegalStateException(e);
    }
}

From source file:com.telefonica.euro_iaas.sdc.installator.InstallatorPuppetTest.java

@Test
public void testLoadNode()
        throws OpenStackException, CanNotCallPuppetException, IOException, InstallatorException {

    when(statusLine.getStatusCode()).thenReturn(200).thenReturn(500);
    when(openStackRegion.getPuppetDBEndPoint(any(String.class))).thenReturn("http");

    InputStream in = IOUtils.toInputStream(GET_NODES, "UTF-8");
    when(entity.getContent()).thenReturn(in);
    PuppetNode node = puppetInstallator.loadNode("aaaa-dddfafff-1-000081", "token");
    assertNotNull(node);//from  w w w  . j av  a2s. com
    assertEquals(node.getName(), "aaaa-dddfafff-1-000081.novalocal");

}

From source file:mitm.common.cache.ContentCacheImplTest.java

@Test
public void testRemoveAllEntries() throws IOException, CacheException {
    FileStreamCacheEntry entry = new FileStreamCacheEntry("body");

    assertFalse(entry.isValid());// ww w .  j  av a2s.  c o  m

    assertNull(entry.getFile(false));

    String content = "Some content";

    entry.store(IOUtils.toInputStream(content, "UTF-8"));

    assertTrue(entry.isValid());

    String key = "key";

    cache.addEntry(key, entry);

    entry = new FileStreamCacheEntry("other body");

    content = "Other content";

    entry.store(IOUtils.toInputStream(content, "UTF-8"));

    cache.addEntry(key, entry);

    List<CacheEntry> entries = cache.getAllEntries(key);

    assertEquals(2, entries.size());

    assertNotNull(cache.getWrapper(key, false));

    cache.removeAllEntries(key);

    assertNull(cache.getWrapper(key, false));
}

From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParser.java

@Override
protected ActivityContext prepareItem(TNTInputStream<?, ?> stream, Object data) throws ParseException {
    Node xmlDoc;//from   ww w  .  jav a 2  s . c  om
    String xmlString = null;
    try {
        if (data instanceof Document) {
            xmlDoc = (Document) data;
        } else if (data instanceof Node) {
            xmlDoc = (Node) data;
        } else {
            xmlString = getNextActivityString(data);
            if (StringUtils.isEmpty(xmlString)) {
                return null;
            }
            synchronized (builder) {
                xmlDoc = builder.parse(IOUtils.toInputStream(xmlString, Utils.UTF8));
            }
        }
    } catch (Exception e) {
        ParseException pe = new ParseException(StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME,
                "ActivityXmlParser.xmlDocument.parse.error"), 0);
        pe.initCause(e);

        throw pe;
    }

    if (xmlString == null) {
        try {
            xmlString = Utils.documentToString(xmlDoc);
        } catch (Exception exc) {
            logger().log(OpLevel.WARNING, StreamsResources.getString(StreamsResources.RESOURCE_BUNDLE_NAME,
                    "ActivityXmlParser.xmlDocument.toString.error"), exc);
        }
    }

    ActivityContext cData = new ActivityContext(stream, data, xmlDoc);
    cData.setMessage(xmlString);

    return cData;
}