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:fi.mystes.synapse.mediator.util.XslTransformer.java

/**
 * Creates XSL transformer./*from ww  w .  j ava  2s.  co m*/
 * 
 * @param xsl XSL style sheet to initialize transformer with
 * 
 * @return Initiated XSL transformer
 * 
 * @throws TransformerConfigurationException If transformer initialization fails
 */
private Transformer createTransformerFor(String xsl) throws TransformerConfigurationException {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    return transformerFactory.newTransformer(new StreamSource(IOUtils.toInputStream(xsl)));
}

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

@Test(expected = IOException.class)
public void getContentInputStream_should_throw_exception_if_header_ends_without_carriage_return_line_feed()
        throws IOException {
    StringBuilder mimeBodyPartStringBuilder = new StringBuilder();
    String header = "header: value\r";
    mimeBodyPartStringBuilder.append(header);
    mimeBodyPartStringBuilder.append("\r\n");
    mimeBodyPartStringBuilder.append(contentString);

    mimeInputStream = IOUtils.toInputStream(mimeBodyPartStringBuilder.toString());

    createObjectUnderTest().getContentInputStream();
}

From source file:com.netflix.ice.basic.BasicS3ApplicationGroupService.java

public boolean saveApplicationGroup(ApplicationGroup appgroup) {
    Map<String, ApplicationGroup> appgroups = getApplicationGroups();
    appgroups.put(appgroup.name, appgroup);

    try {//from   w  w  w  .  j a  v a2 s . com
        String json = getJson(appgroups);
        s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups",
                IOUtils.toInputStream(json), new ObjectMetadata());
        s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "copy_appgroups",
                IOUtils.toInputStream(json), new ObjectMetadata());

        BasicS3ApplicationGroupService.logger.info("saved appgroup " + appgroup);
        return true;
    } catch (JSONException e) {
        logger.error("Error saving appgroup " + appgroup, e);
        return false;
    }
}

From source file:com.cazcade.billabong.store.impl.FileBasedBinaryStoreTest.java

@Test
public void testEntryRemoval() throws IOException {
    StaticTestDateHelper dateHelper = new StaticTestDateHelper();
    dateHelper.setDate(lastModifiedDate);
    FileBasedBinaryStore store = new FileBasedBinaryStore(storeDirectory);
    store.setDateHelper(dateHelper);/*  w  ww. j av  a2 s. c o  m*/

    Assert.assertEquals(0, storeDirectory.list().length);

    InputStream storeEntry = IOUtils.toInputStream("TESTY");
    Assert.assertTrue(store.placeInStore(STORE_KEY, storeEntry, false));
    Assert.assertEquals(1, storeDirectory.list().length);
    Assert.assertTrue(storeFile.exists());
    Assert.assertFalse(storeFile2.exists());

    storeEntry = IOUtils.toInputStream("TESTY2");
    Assert.assertTrue(store.placeInStore(STORE_KEY2, storeEntry, true));
    Assert.assertEquals(2, storeDirectory.list().length);
    Assert.assertTrue(storeFile.exists());
    Assert.assertTrue(storeFile2.exists());

    Assert.assertEquals("TESTY", IOUtils.toString(store.retrieveFromStore(STORE_KEY).getContent()));
    Assert.assertEquals("TESTY2", IOUtils.toString(store.retrieveFromStore(STORE_KEY2).getContent()));

    Assert.assertTrue(store.placeInStore(STORE_KEY, null, true));
    Assert.assertEquals(1, storeDirectory.list().length);
    Assert.assertFalse(storeFile.exists());
    Assert.assertTrue(storeFile2.exists());
}

From source file:dz.alkhwarizmix.framework.java.utils.impl.XMLUtil.java

protected AbstractAlKhwarizmixDomainObject internal_unmarshalObjectFromXML( // NOPMD
        final String xmlValue) {
    return (AbstractAlKhwarizmixDomainObject) jaxb2Marshaller
            .unmarshal(new StreamSource(IOUtils.toInputStream(xmlValue)));
}

From source file:gobblin.data.management.copy.writer.FileAwareInputStreamDataWriterTest.java

@Test
public void testWrite() throws Exception {
    String streamString = "testContents";

    FileStatus status = fs.getFileStatus(testTempPath);
    OwnerAndPermission ownerAndPermission = new OwnerAndPermission(status.getOwner(), status.getGroup(),
            new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));
    CopyableFile cf = CopyableFileUtils.getTestCopyableFile(ownerAndPermission);

    CopyableDatasetMetadata metadata = new CopyableDatasetMetadata(
            new TestCopyableDataset(new Path("/source")));

    WorkUnitState state = TestUtils.createTestWorkUnitState();
    state.setProp(ConfigurationKeys.WRITER_STAGING_DIR, new Path(testTempPath, "staging").toString());
    state.setProp(ConfigurationKeys.WRITER_OUTPUT_DIR, new Path(testTempPath, "output").toString());
    state.setProp(ConfigurationKeys.WRITER_FILE_PATH, RandomStringUtils.randomAlphabetic(5));
    CopySource.serializeCopyEntity(state, cf);
    CopySource.serializeCopyableDataset(state, metadata);

    FileAwareInputStreamDataWriter dataWriter = new FileAwareInputStreamDataWriter(state, 1, 0);

    FileAwareInputStream fileAwareInputStream = new FileAwareInputStream(cf,
            StreamUtils.convertStream(IOUtils.toInputStream(streamString)));
    dataWriter.write(fileAwareInputStream);
    dataWriter.commit();/*from ww  w.j  ava  2 s  . co  m*/
    Path writtenFilePath = new Path(new Path(state.getProp(ConfigurationKeys.WRITER_OUTPUT_DIR),
            cf.getDatasetAndPartition(metadata).identifier()), cf.getDestination());
    Assert.assertEquals(IOUtils.toString(new FileInputStream(writtenFilePath.toString())), streamString);
}

From source file:net.firejack.platform.service.registry.helper.PackageVersionHelper.java

/**
 * @param pkg//  ww w .j a va 2 s .co  m
 * @param version
 * @param xml
 * @throws java.io.IOException
 */
public void archiveVersion(PackageModel pkg, Integer version, String xml) throws IOException {
    for (PackageFileType type : PackageFileType.values()) {
        String name = pkg.getName() + type.getDotExtension();
        InputStream stream = OPFEngine.FileStoreService.download(OpenFlame.FILESTORE_BASE, name,
                helper.getVersion(), String.valueOf(pkg.getId()), String.valueOf(pkg.getVersion()));
        if (stream != null)
            OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, name, stream, helper.getVersion(),
                    String.valueOf(pkg.getId()), String.valueOf(version));
    }

    String name = pkg.getName() + PackageFileType.PACKAGE_XML.getDotExtension();
    InputStream stream = IOUtils.toInputStream(xml);
    OPFEngine.FileStoreService.upload(OpenFlame.FILESTORE_BASE, name, stream, helper.getVersion(),
            String.valueOf(pkg.getId()), version.toString());
    IOUtils.closeQuietly(stream);
}

From source file:eu.learnpad.rest.utils.internal.DefaultRestUtils.java

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

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

private FixDir getFixDirWithTwoFiles1(String fileContent) {
    InputStream inputStream1 = IOUtils.toInputStream(fileContent);
    FixFile file1 = new FixFile(inputStream1);

    InputStream inputStream2 = IOUtils.toInputStream(fileContent);
    FixFile file2 = new FixFile(inputStream2);

    Map<String, FixFsObject> content1 = Maps.newHashMap();
    content1.put("file1", file1);
    content1.put("file2", file2);
    return new FixDir(content1);
}

From source file:com.collective.celos.ci.testing.fixtures.compare.RecursiveFsObjectComparerTest.java

@Test
public void testComparesWrongTypes() throws Exception {
    FixFile file1 = new FixFile(IOUtils.toInputStream("content"));
    FixDir file2 = getFixDirWithTwoFiles1();

    FixObjectCompareResult compareResult = new RecursiveFsObjectComparer(Utils.wrap(file1), Utils.wrap(file2))
            .check(null);//ww  w.  j  a  v  a 2s . c o m
    Assert.assertEquals("RecursiveFsObjectComparer: expected is [File] and actual is [Dir]\n",
            compareResult.generateDescription());
    Assert.assertEquals(compareResult.getStatus(), FixObjectCompareResult.Status.FAIL);
}