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

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

Introduction

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

Prototype

public static List readLines(InputStream input, String encoding) throws IOException 

Source Link

Document

Get the contents of an InputStream as a list of Strings, one entry per line, using the specified character encoding.

Usage

From source file:org.apache.streams.facebook.test.data.FacebookActivityActorSerDeIT.java

@Test
public void Tests() throws Exception {
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);

    InputStream is = FacebookActivityActorSerDeIT.class.getResourceAsStream("/testpage.json");
    is = new BoundedInputStream(is, 10000);
    String json = String.join(" ", IOUtils.readLines(is, Charset.defaultCharset()));
    LOGGER.debug(json);/*from ww w.  j  av a  2  s.co  m*/

    Page page = mapper.readValue(json, Page.class);

    Activity activity = serializer.deserialize(page);

    LOGGER.debug(mapper.writeValueAsString(activity));
}

From source file:org.apache.streams.facebook.test.data.FacebookActivitySerDeIT.java

@Test
public void Tests() {
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);

    InputStream is = FacebookActivitySerDeIT.class.getResourceAsStream("/testpost.json");
    is = new BoundedInputStream(is, 10000);
    String json;//  www  . ja  v a 2  s.c o  m

    try {
        json = String.join(" ", IOUtils.readLines(is, Charset.defaultCharset()));
        LOGGER.debug(json);

        Post post = mapper.readValue(json, Post.class);

        Activity activity = serializer.deserialize(post);

        LOGGER.debug(mapper.writeValueAsString(activity));

    } catch (Exception e) {
        LOGGER.error("Exception: ", e);
        Assert.fail();
    }
}

From source file:org.apache.streams.facebook.test.data.FacebookPageSerDeIT.java

@Test
public void Tests() {
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);

    InputStream is = FacebookPageSerDeIT.class.getResourceAsStream("/testpage.json");
    is = new BoundedInputStream(is, 10000);
    String json;/*from  w w  w.j  av a 2 s  . c  o m*/

    try {
        json = String.join(" ", IOUtils.readLines(is, Charset.defaultCharset()));
        LOGGER.debug(json);

        Page ser = mapper.readValue(json, Page.class);

        String de = mapper.writeValueAsString(ser);

        LOGGER.debug(de);

        Page serde = mapper.readValue(de, Page.class);

        Assert.assertEquals(ser, serde);

        LOGGER.debug(mapper.writeValueAsString(serde));

    } catch (Exception e) {
        LOGGER.error("Exception: ", e);
        Assert.fail();
    }
}

From source file:org.apache.streams.facebook.test.data.FacebookPostSerDeIT.java

@Test
public void Tests() {
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);

    InputStream is = FacebookPostSerDeIT.class.getResourceAsStream("/testpost.json");
    is = new BoundedInputStream(is, 10000);
    String json;/*w  w  w  . ja  v a2  s.c om*/

    try {
        json = String.join(" ", IOUtils.readLines(is, Charset.defaultCharset()));
        LOGGER.debug(json);

        Post ser = mapper.readValue(json, Post.class);

        String de = mapper.writeValueAsString(ser);

        LOGGER.debug(de);

        Post serde = mapper.readValue(de, Post.class);

        assertEquals(ser, serde);

        LOGGER.debug(mapper.writeValueAsString(serde));

        Activity activity = new Activity();
        FacebookActivityUtil.updateActivity(ser, activity);

        assertNotNull(activity);
        assertNotNull(activity.getActor().getId());
        assertNotNull(activity.getActor().getDisplayName());
        assertNotNull(activity.getId());
        assert (activity.getVerb().equals("post"));
        assertNotNull(activity.getObject());
        assertNotNull(activity.getUpdated());
        assertNotNull(activity.getPublished());
        assertEquals(activity.getProvider().getId(), "id:providers:facebook");
        assertEquals(activity.getProvider().getDisplayName(), "Facebook");
        assertEquals(activity.getLinks().size(), 1);
        assertNotNull(activity.getAdditionalProperties().get("facebook"));

    } catch (Exception e) {
        LOGGER.error("Exception: ", e);
        Assert.fail();
    }
}