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.collective.celos.ci.testing.fixtures.convert.FixDirRecursiveConverterTest.java

private FixDir createDirWithFileContent(String fileContent) {
    FixDir dir1 = createDirWithSubdirsAndFile(fileContent);
    InputStream inputStream2 = IOUtils.toInputStream(fileContent);
    FixFile file = new FixFile(inputStream2);

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

From source file:com.smartitengineering.dao.impl.hbase.JsonConfigLoaderTest.java

@Test
public void deserializeFilterConfigsFromSerializedString() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    StringWriter writer = new StringWriter();
    mapper.writeValue(writer, CONFIGS);/*from   ww w . j a  v a  2s  .co m*/
    InputStream stream = IOUtils.toInputStream(writer.toString());
    FilterConfigs readConfigs = JsonConfigLoader.parseJsonAsFilterConfigMap(stream);
    Assert.assertEquals(CONFIGS, readConfigs);
}

From source file:de.tudarmstadt.ukp.uby.ubycreate.WordNetCreator.java

@Override
public File lexicon2XML(String source, File lmfXML)
        throws IOException, XMLStreamException, SAXException, DocumentException, JWNLException {

    String lexicalResourceName = "WordNet_3.0_eng";

    /* Dumping lexical into a file */

    LexicalResource lexicalResource = null;

    File wnPath = new File(source);
    Dictionary extWordnet;//w  w  w.  ja  va2s  . c  om
    extWordnet = Dictionary.getInstance(IOUtils.toInputStream("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<jwnl_properties language=\"en\">"
            + "    <version publisher=\"Princeton\" number=\"3.0\" language=\"en\"/>"
            + "    <dictionary class=\"net.sf.extjwnl.dictionary.FileBackedDictionary\">"
            + "        <param name=\"morphological_processor\" value=\"net.sf.extjwnl.dictionary.morph.DefaultMorphologicalProcessor\">"
            + "            <param name=\"operations\">"
            + "                <param value=\"net.sf.extjwnl.dictionary.morph.LookupExceptionsOperation\"/>"
            + "                <param value=\"net.sf.extjwnl.dictionary.morph.DetachSuffixesOperation\">"
            + "                    <param name=\"noun\" value=\"|s=|ses=s|xes=x|zes=z|ches=ch|shes=sh|men=man|ies=y|\"/>"
            + "                    <param name=\"verb\" value=\"|s=|ies=y|es=e|es=|ed=e|ed=|ing=e|ing=|\"/>"
            + "                    <param name=\"adjective\" value=\"|er=|est=|er=e|est=e|\"/>"
            + "                    <param name=\"operations\">"
            + "                        <param value=\"net.sf.extjwnl.dictionary.morph.LookupIndexWordOperation\"/>"
            + "                        <param value=\"net.sf.extjwnl.dictionary.morph.LookupExceptionsOperation\"/>"
            + "                    </param>" + "                </param>"
            + "                <param value=\"net.sf.extjwnl.dictionary.morph.TokenizerOperation\">"
            + "                    <param name=\"delimiters\">" + "                        <param value=\" \"/>"
            + "                        <param value=\"-\"/>" + "                    </param>"
            + "                    <param name=\"token_operations\">"
            + "                        <param value=\"net.sf.extjwnl.dictionary.morph.LookupIndexWordOperation\"/>"
            + "                        <param value=\"net.sf.extjwnl.dictionary.morph.LookupExceptionsOperation\"/>"
            + "                        <param value=\"net.sf.extjwnl.dictionary.morph.DetachSuffixesOperation\">"
            + "                            <param name=\"noun\" value=\"|s=|ses=s|xes=x|zes=z|ches=ch|shes=sh|men=man|ies=y|\"/>"
            + "                            <param name=\"verb\" value=\"|s=|ies=y|es=e|es=|ed=e|ed=|ing=e|ing=|\"/>"
            + "                            <param name=\"adjective\" value=\"|er=|est=|er=e|est=e|\"/>"
            + "                            <param name=\"operations\">"
            + "                                <param value=\"net.sf.extjwnl.dictionary.morph.LookupIndexWordOperation\"/>"
            + "                                <param value=\"net.sf.extjwnl.dictionary.morph.LookupExceptionsOperation\"/>"
            + "                            </param>" + "                        </param>"
            + "                    </param>" + "                </param>" + "            </param>"
            + "        </param>" + "        <param name=\"dictionary_element_factory\""
            + "               value=\"net.sf.extjwnl.princeton.data.PrincetonWN17FileDictionaryElementFactory\"/>"
            + "        <param name=\"file_manager\" value=\"net.sf.extjwnl.dictionary.file_manager.FileManagerImpl\">"
            + "            <param name=\"file_type\" value=\"net.sf.extjwnl.princeton.file.PrincetonRandomAccessDictionaryFile\">"
            + "                <!--<param name=\"write_princeton_header\" value=\"true\"/>-->"
            + "                <!--<param name=\"encoding\" value=\"UTF-8\"/>-->" + "            </param>"
            + "            <!--<param name=\"cache_use_count\" value=\"true\"/>-->"
            + "            <param name=\"dictionary_path\" value=\"" + wnPath.getAbsolutePath() + "\"/>"
            + "        </param>" + "    </dictionary>"
            + "    <resource class=\"net.sf.extjwnl.princeton.PrincetonResource\"/>" + "</jwnl_properties>"));

    WNConverter converterWN = new WNConverter(wnPath, extWordnet, new LexicalResource(), lexicalResourceName,
            dtdVersion);
    converterWN.toLMF();
    lexicalResource = converterWN.getLexicalResource();

    LMFXmlWriter xmlWriter = new LMFXmlWriter(lmfXML.getAbsolutePath(), dtdPath);
    xmlWriter.writeElement(lexicalResource);
    xmlWriter.writeEndDocument();

    System.out.println("temp file saved: " + lmfXML.getAbsolutePath());

    return lmfXML;

}

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

@Override
protected InputStream addLinks(final String entitySetName, final String entitykey, final InputStream is,
        final Set<String> links) throws Exception {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
    IOUtils.closeQuietly(is);// w w w .j  a  v a2  s  .com

    for (String link : links) {
        srcNode.set(link + JSON_NAVIGATION_SUFFIX,
                new TextNode(Commons.getLinksURI(version, entitySetName, entitykey, link)));
    }

    return IOUtils.toInputStream(srcNode.toString());
}

From source file:com.duroty.lucene.parser.ParserFactory.java

/**
 * DOCUMENT ME!/*from   ww w  .  j  ava  2s.c  om*/
 *
 * @param str DOCUMENT ME!
 * @param mimetype DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public String parse(String str, String mimetype, String charset) {
    if ((str == null) || str.trim().equals("")) {
        return null;
    }

    InputStream input = null;

    String className = (String) parseFactoryConfig.get(mimetype);

    //log.info("PARSE ATTACHMENT: " + className + " >> " + mimetype);
    if (className == null) {
        return null;
    }

    try {
        Class clazz = Class.forName(className);

        Parser parser = (Parser) clazz.newInstance();

        parser.setCharset(MimeUtility.javaCharset(charset));

        input = IOUtils.toInputStream(str);

        return parser.parse(input);
    } catch (ClassNotFoundException e) {
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    } catch (ParserException e) {
    } catch (Exception e) {
    } finally {
        IOUtils.closeQuietly(input);
    }

    return null;
}

From source file:info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapterRepositoryTest.java

@Override
@Before/*w w w  .  java  2s.  co  m*/
public void setUp() throws Exception {
    super.setUp();
    // Init parent Node
    String nodeProperties = "/parent.@type=mgnl:content\n" + "/parent.propertyString=hello\n"
            + "/parent/child.@type=mgnl:content\n" + "/parent/child.propertyString=chield1\n";

    Session session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
    new PropertiesImportExport().createNodes(session.getRootNode(), IOUtils.toInputStream(nodeProperties));
    session.save();

    node = session.getRootNode().getNode(nodeName);
}

From source file:jazsync.UploadTests.java

@Test
public void testParseRelocatesAndByteRanges() throws UnsupportedEncodingException, IOException {

    String uploadString = version + blocksize + filelength + someKV + sha1 + relocString + rangeString;

    Upload um = Upload.parse(IOUtils.toInputStream(uploadString));

    String expRelocs = relocString;
    String actRelocs = IOUtils.toString(um.getRelocStream(), "US-ASCII");
    actRelocs = "Relocate:" + actRelocs + "\n";

    String expRanges = rangeString;
    String actRanges = IOUtils.toString(um.getDataStream(), "US-ASCII");
    actRanges = "\n" + actRanges;

    Assert.assertEquals(expRelocs, actRelocs);
    Assert.assertEquals(expRanges, actRanges);
}

From source file:info.joseluismartin.gtc.TmsCache.java

/**
 * {@inheritDoc}//from w ww  .j a  v a  2  s .  c  o  m
 */
@Override
public InputStream parseResponse(InputStream serverStream, String remoteUri, String localUri)
        throws IOException {
    String response = IOUtils.toString(serverStream);
    response = response.replaceAll(getServerUrl(), localUri + "/" + getPath());

    return IOUtils.toInputStream(response);
}

From source file:de.thischwa.pmcms.model.tool.ImportBackup.java

@Override
public void run() {
    logger.info("Try to import site from file: " + zipFile.getName());
    siteHolder.clear();//w  w w  .ja  v a  2s.  c om
    ZipInfo zipInfo;
    try {
        zipInfo = Zip.getEntryInfo(zipFile);
    } catch (IOException e1) {
        throw new FatalException("While getting infos for zip entries: " + e1.getMessage(), e1);
    }
    SAXReader reader = new SAXReader();
    reader.setEncoding(Constants.STANDARD_ENCODING);
    try {
        String xml = IOUtils.toString(zipInfo.getInputStream("db.xml"));
        // clean up invalid xml chars
        xml = Utils.stripNonValidXMLCharacters(xml);

        Document document = reader.read(IOUtils.toInputStream(xml));
        Element root = document.getRootElement();
        IBackupParser backupParser;
        String version = root.attributeValue("version");
        if (StringUtils.isBlank(version)) {
            backupParser = new BackupParser_old(root);
        } else if (version.equals(IBackupParser.DBXML_1) || version.equals(IBackupParser.DBXML_2)) {
            backupParser = new BackupParser_1(root, version);
        } else {
            throw new RuntimeException(String.format("No backup parser found for version %s.", version));
        }
        backupParser.setMonitor(monitor);
        backupParser.run();
        site = backupParser.getSite();
    } catch (Exception e) {
        e.printStackTrace();
        throw new FatalException("While reading db.xml: " + e.getMessage(), e);
    }

    if (this.monitor != null)
        this.monitor.done();

    // unzip
    try {
        zipInfo.removeEntry("db.xml");
        if (monitor != null)
            monitor.beginTask(
                    LabelHolder.get("zip.extract").concat(String.valueOf(zipInfo.getEntryKeys().size())), //$NON-NLS-1$
                    zipInfo.getEntryKeys().size());
        Zip.extract(InitializationManager.getSitesDir(), zipInfo, monitor);
    } catch (IOException e) {
        throw new FatalException("While unzipping files: " + e.getMessage(), e);
    }

    logger.debug("[" + site.getUrl() + "] successfull imported.");
}

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

private FixDir createDirWithSubdirsAndFile() {
    FixDir dir1 = getFixDirWithTwoFiles1();
    FixDir dir2 = getFixDirWithTwoFiles1();
    InputStream inputStream2 = IOUtils.toInputStream("stream");
    FixFile file = new FixFile(inputStream2);

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