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

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

Introduction

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

Prototype

public static String toString(byte[] input) throws IOException 

Source Link

Document

Get the contents of a byte[] as a String using the default character encoding of the platform.

Usage

From source file:com.linkedin.gradle.python.util.pex.DefaultPexEntryPointTemplateProvider.java

@Override
public String retrieveTemplate(TemplateProviderOptions options, boolean isPythonWrapper) throws IOException {
    PythonExtension extension = options.getExtension();
    CliExtension cliExtension = ExtensionUtils.findPythonComponentExtension(extension, CliExtension.class);
    if (cliExtension != null && isPythonWrapper) {
        return IOUtils.toString(DefaultPexEntryPointTemplateProvider.class
                .getResourceAsStream("/templates/pex_cli_entrypoint.py.template"));
    } else {/*w w w . ja  v a 2  s  . c  om*/
        return IOUtils.toString(DefaultPexEntryPointTemplateProvider.class
                .getResourceAsStream("/templates/pex_non_cli_entrypoint.sh.template"));
    }
}

From source file:io.sidecar.org.CredentialJsonValidationTest.java

@BeforeMethod
public void loadValidEventJsonAsString() throws Exception {
    validProvisionAsJson = IOUtils.toString(this.getClass().getResource("/credential_access_payload.json"));
    credentialAsObjectNode = (ObjectNode) mapper.readTree(validProvisionAsJson);
}

From source file:ch.tatool.core.exec.SpringExecutorInitializerTest.java

/**
 * Tests whether the Spring configuration file can be loaded ok
 *//*  w w w. java 2 s . c  om*/
@Test
public void testLoadConfigurationFromFile() throws IOException {
    // load configuration file
    String testConfiguration = IOUtils
            .toString(getClass().getResourceAsStream("/configurations/test-module-configuration.xml"));

    // load the configuration properties
    Map<String, String> moduleProps = new HashMap<String, String>();
    Map<String, byte[]> binaryModuleProps = new HashMap<String, byte[]>();
    Map<String, DataExporter> moduleExporters = new HashMap<String, DataExporter>();
    SpringExecutorInitializer configuration = new SpringExecutorInitializer();
    configuration.loadModuleConfiguration(testConfiguration, moduleProps, binaryModuleProps, moduleExporters);
}

From source file:de.psdev.licensesdialog.licenses.License.java

protected String getContent(final Context context, final int contentResourceId) {
    InputStream inputStream = null;
    try {/*ww w.ja  va 2s  .c om*/
        inputStream = context.getResources().openRawResource(contentResourceId);
        return IOUtils.toString(inputStream);
    } catch (IOException e) {
        Log.e("LicenseDialog", e.getMessage(), e);
        return "";
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:com.linkedin.gradle.python.util.pex.DefaultEntryPointTemplateProvider.java

@Override
public String retrieveTemplate(TemplateProviderOptions options) throws IOException {
    PythonExtension extension = options.getExtension();
    PexExtension pexExtension = ExtensionUtils.getPythonComponentExtension(extension, PexExtension.class);
    CliExtension cliExtension = ExtensionUtils.findPythonComponentExtension(extension, CliExtension.class);
    if (cliExtension != null && pexExtension.isPythonWrapper()) {
        return IOUtils.toString(DefaultEntryPointTemplateProvider.class
                .getResourceAsStream("/templates/pex_cli_entrypoint.py.template"));
    } else {/*from w w  w . j  av a  2 s.  c o  m*/
        return IOUtils.toString(DefaultEntryPointTemplateProvider.class
                .getResourceAsStream("/templates/pex_non_cli_entrypoint.sh.template"));
    }
}

From source file:com.aestasit.markdown.slidery.SlideryTest.java

@Test
public void testLoadingMethods() throws IOException {
    // from InputStream
    validateSlides(toSlides(allTestData()));
    // from File/*from  ww  w .java  2s  .c  o m*/
    validateSlides(toSlides(allTestData()));
    // from URL
    validateSlides(toSlides(classpath("01_simple_slides.md").toURI().toURL()));
    // from String 
    validateSlides(toSlides(IOUtils.toString(allTestData())));
}

From source file:com.jive.myco.seyren.core.util.velocity.VelocityEmailHelper.java

private static String getTemplateAsString() {
    try {/* w  w w  .jav a  2  s. co  m*/
        return IOUtils.toString(
                Thread.currentThread().getContextClassLoader().getResourceAsStream(TEMPLATE_FILE_NAME));
    } catch (IOException e) {
        throw new RuntimeException("Template file could not be found on classpath at " + TEMPLATE_FILE_NAME);
    }
}

From source file:ch.sbb.releasetrain.action.SendMailActionTest.java

@org.junit.Before
public void setUp() throws Exception {

    String in = IOUtils.toString(getClass().getResourceAsStream("/test-mail-action-state.yml"));
    YamlModelAccessor<ActionState> yaml = new YamlModelAccessor<>();
    mailState = yaml.convertEntry(in);/*w w w .  jav a2s . c  o m*/
    server = SimpleSmtpServer.start(2525);

    SMTPUtilImpl smtp = new SMTPUtilImpl();
    smtp.setMailhost("localhost");
    smtp.setMailport(2525);

    action = new SendMailAction();
    action.setConfig(config);
    action.setSmtpUtil(smtp);

    action.setConfig(config);

    List<MailReceiver> receiverList = new ArrayList<>();

    when(mailRec.getEmail()).thenReturn("bla@bla.bl");
    receiverList.add(mailRec);
    when(config.readMailReveiverForMailinglist(anyString())).thenReturn(receiverList);

}

From source file:com.opinionlab.woa.WallOfAwesomeTest.java

@Test
public void hello() throws IOException {
    CloseableHttpResponse response = HttpClients.createDefault()
            .execute(new HttpGet("http://localhost:9999/hello"));
    assertEquals("Hello World!", IOUtils.toString(response.getEntity().getContent()));
}

From source file:com.machinelinking.exporter.TextCSVExporterTest.java

@Test
public void testExport() throws IOException {
    final TextCSVExporter exporter = new TextCSVExporter();
    exporter.setThreads(1);//from   w w  w .j ava 2  s.c om
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    exporter.export(new URL("http://it.wikipedia.org/"),
            FileUtil.openDecompressedInputStream("/dumps/enwiki-latest-pages-articles-p1.xml.gz"), out);

    final String expected = IOUtils.toString(this.getClass().getResourceAsStream("text-out.csv"));
    Assert.assertEquals(out.toString(), expected);
}