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

Source Link

Document

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

Usage

From source file:me.vertretungsplan.parser.ColumnTypeDetector.java

public ColumnTypeDetector() throws IOException, JSONException {
    columns = new HashMap<>();
    InputStream is = getClass().getClassLoader().getResourceAsStream("column_headers.json");
    String content = IOUtils.toString(is, "UTF-8");
    JSONObject json = new JSONObject(content);
    for (Iterator it = json.keys(); it.hasNext();) {
        String type = (String) it.next();
        final JSONArray titles = json.getJSONArray(type);
        for (int i = 0; i < titles.length(); i++) {
            columns.put(titles.getString(i), type);
        }//w  w w . j a  v  a  2 s .  c om
    }
}

From source file:com.netsteadfast.greenstep.util.ExportData2CsvUtils.java

private static ExportDataConfig getConfig(String configXmlFile) throws Exception {
    InputStream is = ExportData2CsvUtils.class.getClassLoader().getResource(META_CONF_DIR + "/" + configXmlFile)
            .openStream();//from  www  .  j  a  v a2s  .c o m
    byte[] xmlContent = IOUtils.toString(is, Constants.BASE_ENCODING).getBytes();
    JAXBContext jaxbContext = JAXBContext.newInstance(ExportDataConfig.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    ByteArrayInputStream bais = new ByteArrayInputStream(xmlContent);
    ExportDataConfig config = (ExportDataConfig) jaxbUnmarshaller.unmarshal(bais);
    return config;
}

From source file:com.github.dozermapper.spring.functional_tests.SchemaLocationTest.java

@Test
public void ensureHttpsSchemaAccessible() throws IOException {
    URI uri = URI.create("https://dozermapper.github.io/schema/dozer-spring.xsd");
    String value = IOUtils.toString(uri, "utf-8");
    Assert.assertTrue(value.contains("http://dozermapper.github.io/schema/dozer-spring"));
}

From source file:de.elomagic.vaadin.addon.speechrecognition.SpeechRecognitionEventDataTest.java

private String readJsonFile1() throws IOException {
    return IOUtils.toString(getClass().getClassLoader().getResourceAsStream("events/event1.json"), "utf-8");
}

From source file:costumetrade.common.util.HttpClientUtils.java

public static String doPost(String url, HttpEntity httpEntity) {

    logger.info("?{}....", url);

    try (CloseableHttpClient httpclient = HttpClients.custom().build();) {
        HttpPost request = new HttpPost(url);
        request.setEntity(httpEntity);/*from  w  w w .j  a  va2s.c  o m*/
        try (CloseableHttpResponse response = httpclient.execute(request);) {
            int statusCode = response.getStatusLine().getStatusCode();
            logger.info("?{}???{}", url, statusCode);
            if (HttpStatus.SC_OK == statusCode) {
                return IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8.name());
            }
            throw new RuntimeException(String.format("?%s???%s", url, statusCode));
        }
    } catch (Exception e) {
        throw new RuntimeException(String.format("%s", url), e);
    }
}

From source file:cucumber.scratch.maven.react.io.Resources.java

public String toString(String classPath) throws IOException {
    return IOUtils.toString(toInputStream(classPath), "UTF-8");
}

From source file:de.cosmocode.palava.core.AsciiArt.java

/**
 * Prints the palava ascii art by first checking the file lib/palava-ascii.txt
 * and in case it does not exist uses the classpath resource palava-ascii.txt.
 * Prints a warning if none exists.// www.  java2 s . co  m
 */
public static void print() {
    try {
        final InputStream stream = open();
        final String message = IOUtils.toString(stream, "UTF-8");
        LOG.info("Welcome to\n{}", message);
    } catch (IOException e) {
        LOG.warn("Unable to print ascii art", e);
    }
}

From source file:com.byteatebit.common.io.TestAbsoluteClasspathStreamSource.java

@Test
public void testGetInputStream() throws IOException {
    IStreamSource streamSource = new AbsoluteClasspathStreamSource("io/classpath_resource.txt");
    try (InputStream in = streamSource.getInputStream()) {
        String message = IOUtils.toString(in, StandardCharsets.UTF_8);
        Assert.assertEquals("Sample classpath resource", message);
    }/*from  w  ww  .  j a  v a2  s.co  m*/
}

From source file:com.floatboth.antigravity.ui.LicenseActivity.java

@AfterViews
public void setUpViews() {
    try {/*from  w  ww  .  ja v  a  2s.co  m*/
        InputStream is = getAssets()
                .open(uri.toString().replace("com.floatboth.antigravity.license://", "license_") + ".txt");
        app_info.setText(IOUtils.toString(is, "UTF-8"));
        Linkify.addLinks(app_info, Linkify.WEB_URLS);
        app_info.setMovementMethod(LinkMovementMethod.getInstance());
    } catch (Exception ex) {
    }
}

From source file:com.thoughtworks.go.util.ZipUtilTest.java

private static String fileContent(File file) throws IOException {
    return IOUtils.toString(new FileInputStream(file), UTF_8);
}