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.galenframework.ide.tests.unit.DomSnapshotTest.java

@Test
public void shouldReplace_allLinks_andRemoveScripts() throws IOException {
    String originSource = IOUtils.toString(getClass().getResourceAsStream("/some-source-origin.html"));
    String expectedResult = IOUtils.toString(getClass().getResourceAsStream("/sanitized-source.html"));

    DomSnapshot domSnapshot = DomSnapshot.createSnapshotAndReplaceUrls(originSource,
            "http://another.example.com");

    assertEquals(trimEveryLine(domSnapshot.getOriginSource()), expectedResult);
}

From source file:com.github.terma.m.shared.Config.java

public static Config readConfig() {
    final String configPath = System.getProperty(CONFIG_PATH_SYSTEM_PROPERTY);
    if (configPath == null)
        throw new IllegalArgumentException("No config property -D" + CONFIG_PATH_SYSTEM_PROPERTY);

    if (configPath.startsWith(CLASSPATH_PREFIX)) {
        InputStream inputStream = Config.class
                .getResourceAsStream(configPath.substring(CLASSPATH_PREFIX.length()));
        if (inputStream == null)
            throw new IllegalArgumentException("Can't find config in classpath by: " + configPath);

        try {/*  w ww . jav a  2  s.co m*/
            return new Gson().fromJson(IOUtils.toString(inputStream), Config.class);
        } catch (IOException e) {
            throw new IllegalArgumentException("Invalid path to config: " + configPath + " set by property -D"
                    + CONFIG_PATH_SYSTEM_PROPERTY + "!", e);
        }
    } else if (configPath.startsWith(FILE_PREFIX)) {
        try {
            return new Gson().fromJson(new FileReader(configPath.substring(FILE_PREFIX.length())),
                    Config.class);
        } catch (IOException e) {
            throw new IllegalArgumentException("Invalid path to config: " + configPath + " set by property -D"
                    + CONFIG_PATH_SYSTEM_PROPERTY + "!", e);
        }
    } else if (configPath.startsWith(IGNORE_PREFIX)) {
        // skip for test and other
        return new Config();
    } else {
        throw new UnsupportedOperationException("Unsupported type of config path: " + configPath);
    }
}

From source file:com.sishuok.chapter4.web.servlet.UploadServlet3.java

@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    Part part = req.getPart("file1");
    InputStream is = part.getInputStream();
    System.out.println(IOUtils.toString(is));
    is.close();/* w ww . jav  a  2s .c o  m*/

    /**
     * jetty
     * fileSizeThreshold
     * 1?content-disposition???
     * 2??byte array input stream
     * 3?[2]?fileSizeThreshold
     *
     * 4??
     * 4.1?@MultipartConfiglocation?
     * 4.2?Part.write ?
     *
     */

}

From source file:com.blandware.android.atleap.test.DeserializeTestCase.java

public void testBooksAuthors() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    String jsonString = IOUtils.toString(getContext().getResources().getAssets().open(BOOKS_FILENAME));

    Book.BooksResult result = objectMapper.readValue(jsonString, Book.BooksResult.class);

    assertTrue(result.resultCode == 100);
    assertTrue(result.getBooks() != null);
    assertTrue(result.getBooks().size() == 2);

    assertTrue(result.getBooks().toArray(new Book[0])[0].getAuthors() != null);
    assertTrue(result.getBooks().toArray(new Book[0])[0].getAuthors().size() == 2);

    assertTrue(result.getBooks().toArray(new Book[0])[0].getTags() != null);
    assertTrue(result.getBooks().toArray(new Book[0])[0].getTags().size() == 2);

}

From source file:com.exzogeni.dk.http.callback.StringCallback.java

@Override
public String onSuccess(int statusCode, @NonNull Map<String, List<String>> headers,
        @NonNull InputStream content) throws Exception {
    final String result = IOUtils.toString(content);
    onSuccess(statusCode, headers, result);
    return result;
}

From source file:io.ingenieux.lambada.invoker.fixtures.Fixture.java

public void doSomethingRaw(InputStream is, OutputStream os) throws Exception {
    Integer value = Integer.valueOf(IOUtils.toString(is));

    IOUtils.write("" + (2 * value), os);
}

From source file:com.groupon.jenkins.util.ResourceUtils.java

private static String readFile(Class<?> resourceClass, String ymlResource) {
    InputStream base = null;/*from ww  w .  j  av a 2 s  . c  o  m*/
    try {
        base = resourceClass.getResourceAsStream(ymlResource);
        return IOUtils.toString(base);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(base);
    }
}

From source file:com.collective.celos.ci.testing.fixtures.create.StringFixObjectCreatorTest.java

@Test
public void testStringFixObjectCreator() throws Exception {
    FixFileFromStringCreator creator = new FixFileFromStringCreator(SOME_TEXT);
    FixFile fixFile = creator.create(null);
    Assert.assertEquals(SOME_TEXT, IOUtils.toString(fixFile.getContent()));
}

From source file:io.sidecar.notification.NotificationJsonValidationTest.java

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

From source file:com.alibaba.json.test.Bug_0_Test.java

protected void setUp() throws Exception {
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/Bug_0_Test.json");
    text = IOUtils.toString(is);
    is.close();/*w  ww.  j  ava 2  s  .c om*/

    // text =
    // "[{\"S\":321061,\"T\":\"GetAttributeResp\"},{\"ERROR\":null,\"TS\":0,\"VAL\":{\"SqlList\":[{\"BatchSizeMax\":0,\"BatchSizeTotal\":0,\"ConcurrentMax\":1,\"DataSource\":\"jdbc:wrap-jdbc:filters=default,encoding:name=ds-offer:jdbc:mysql://172.29.61.63:8066/amoeba\",\"EffectedRowCount\":0,\"ErrorCount\":0,\"ExecuteCount\":5,\"FetchRowCount\":5,\"File\":null,\"ID\":2001,\"LastError\":null,\"LastTime\":1292742908178,\"MaxTimespan\":16,\"MaxTimespanOccurTime\":1292742668191,\"Name\":null,\"RunningCount\":0,\"SQL\":\"SELECT @@SQL_MODE\",\"TotalTime\":83}]}}]";
}