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:com.nestlabs.sdk.MetadataTest.java

@Test
public void testCreateMetadataWithJacksonMapper_shouldSetAllValuesCorrectly() {
    try {//  ww  w.ja  va  2s  . c om
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_METADATA_JSON), "utf-8").trim();
        Metadata metadata = mapper.readValue(json, Metadata.class);

        assertEquals(metadata.getAccessToken(), "c.FmDPkzyzaQeX");
        assertEquals(metadata.getClientVersion(), 1);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:com.nestlabs.sdk.SmokeCOAlarmAndroidTest.java

@Test
public void testSmokeCoAlarmToParcel() {
    try {//  ww w. j  a  va2 s .c  om
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_SMOKE_ALARM_JSON), "utf-8");
        SmokeCOAlarm smokeCOAlarm = mapper.readValue(json, SmokeCOAlarm.class);

        Parcel parcel = Parcel.obtain();
        smokeCOAlarm.writeToParcel(parcel, 0);

        parcel.setDataPosition(0);

        SmokeCOAlarm cameraFromParcel = SmokeCOAlarm.CREATOR.createFromParcel(parcel);
        assertEquals(smokeCOAlarm, cameraFromParcel);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:de.elomagic.mag.ConfigurationTest.java

@Before
public void beforeConfigurationTest() throws Exception {
    String text = IOUtils.toString(getClass().getResourceAsStream("/configuration.properties"), "utf-8");
    Files.write(text, file, StandardCharsets.UTF_8);
}

From source file:io.wcm.devops.conga.generator.handlebars.CharsetAwareTemplateSource.java

@Override
public String content() throws IOException {
    try (InputStream is = file.getInputStream()) {
        return IOUtils.toString(is, charset);
    }//from   w  w  w .  ja  va 2s.c o  m
}

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

@Test
public void testGetInputStream() throws IOException {
    File file = tempFolder.newFile("file1.txt");
    String message = "Sample message";
    FileUtils.write(file, message, StandardCharsets.UTF_8);
    IStreamSource streamSource = new FileStreamSource(file);
    try (InputStream in = streamSource.getInputStream()) {
        String fileMessage = IOUtils.toString(in, StandardCharsets.UTF_8);
        Assert.assertEquals(message, fileMessage);
    }//from ww w . j a va  2s .co m
}

From source file:com.epam.wilma.webapp.config.servlet.stub.download.helper.ByteArrayConverter.java

/**
 * Converts a byte array into string using UTF-8 character encoding.
 * @param xml the byte array to be converted
 * @return the result of the conversion// ww  w  .  j a  v a2  s  .  c  om
 * @throws IOException if an I/O error occurs during conversion
 */
public String toString(final byte[] xml) throws IOException {
    return IOUtils.toString(xml, "UTF-8");
}

From source file:com.newtranx.util.io.TestIteratorInputStream.java

@Test
public void testString() throws IOException {
    List<String> list = Collections.singletonList("abc");
    IteratorInputStream<String> is = IteratorInputStream.newBuilder(list.iterator()).bufferSize(10240)
            .encoder((s, buf) -> buf.put(s.getBytes(cs))).build();

    String abc = IOUtils.toString(is, cs);
    assertEquals("abc", abc);
}

From source file:ivorius.ivtoolkit.tools.IvDependencyLoaderMC.java

@Override
public String loadResourceRaw(String location) throws LoadException {
    try {/*from   ww  w.  ja va  2 s .  c  o m*/
        IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
        IResource vShaderRes = resourceManager.getResource(new ResourceLocation(location));
        return IOUtils.toString(vShaderRes.getInputStream(), Charsets.UTF_8);
    } catch (Throwable e) {
        throw new LoadException(e);
    }
}

From source file:com.bunjlabs.fuga.foundation.content.InputStreamContent.java

@Override
public String asString(Charset charset) {
    try {/*from  w w  w  .  j a v  a2  s .co m*/
        return IOUtils.toString(is, charset);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.cognifide.aet.executor.xmlparser.xml.utils.EscapeUtilsTest.java

private String readContentFromFile(String path) throws IOException {
    URL resourceURL = getClass().getResource(path);
    return IOUtils.toString(new FileInputStream(resourceURL.getPath()), "UTF-8");
}