Example usage for java.io BufferedReader ready

List of usage examples for java.io BufferedReader ready

Introduction

In this page you can find the example usage for java.io BufferedReader ready.

Prototype

public boolean ready() throws IOException 

Source Link

Document

Tells whether this stream is ready to be read.

Usage

From source file:org.apache.streams.twitter.test.InstagramActivitySerDeTest.java

@Test
public void TestUserInfoData() {
    InstagramDeserializer instagramDeserializer = new InstagramDeserializer("");
    InputStream is = InstagramActivitySerDeTest.class.getResourceAsStream("/testUserInfoData.txt");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    try {/*w ww. ja  v  a2  s.c om*/
        while (br.ready()) {
            String line = br.readLine();
            if (!StringUtils.isEmpty(line)) {
                LOGGER.info("raw: {}", line);

                UserInfoData userInfoData = instagramDeserializer.createObjectFromResponse(UserInfoData.class,
                        line);

                Activity activity = new Activity();

                LOGGER.info("activity: {}", activity.toString());

                updateActivity(userInfoData, activity);
                assertThat(activity, is(not(nullValue())));

                assertThat(activity.getId(), is(nullValue()));
                assertThat(activity.getActor(), is(not(nullValue())));
                assertThat(activity.getActor().getImage(), is(not(nullValue())));
                assertThat(activity.getActor().getDisplayName(), is(not(nullValue())));
                assertThat(activity.getActor().getSummary(), is(not(nullValue())));

                Map<String, Object> extensions = (Map<String, Object>) activity.getActor()
                        .getAdditionalProperties().get("extensions");
                assertThat(extensions, is(not(nullValue())));
                assertThat(extensions.get("follows"), is(not(nullValue())));
                assertThat(extensions.get("followers"), is(not(nullValue())));
                assertThat(extensions.get("screenName"), is(not(nullValue())));
                assertThat(extensions.get("posts"), is(not(nullValue())));
                assertThat(((Map<String, Object>) activity.getAdditionalProperties().get("extensions"))
                        .get("instagram"), is(not(nullValue())));

                assertThat(activity.getActor().getAdditionalProperties().get("handle"), is(not(nullValue())));
                assertThat(activity.getActor().getId(), is(not(nullValue())));
                assertThat(activity.getActor().getUrl(), is(not(nullValue())));
                assertThat(activity.getVerb(), is(not(nullValue())));
                assertThat(activity.getProvider(), is(not(nullValue())));
                assertThat(activity.getPublished(), is(not(nullValue())));
            }
        }
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:com.pironet.tda.LogFileContent.java

/**
 * read the content in the soft reference object, currently used
 * StringBuffer to maintain 1.4 compability. Should be switched
 * to StringReader if switched to 1.5 for better performance as
 * synchronization is not needed here.// ww  w. j  a  v  a 2s  .c  o  m
 */
private void readContent() {
    final StringBuffer contentReader = new StringBuffer();
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(getLogfile()));
        while (br.ready()) {
            contentReader.append(br.readLine());
            contentReader.append('\n');
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        contentReader.append("The Logfile unavailable! ").append(ex.getMessage());
    } finally {
        IOUtils.closeQuietly(br);
    }
    content = new SoftReference<>(contentReader);
}

From source file:lv.coref.lv.Dictionary.java

public Dictionary readFile(String filename) {
    try {//from   ww  w .jav a 2 s.  c o  m
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        String s;
        while (reader.ready()) {
            s = reader.readLine();
            if (s.trim().length() > 0) {
                String[] bits = s.split("\t");
                if (bits.length > 1)
                    add(bits[1], bits[0]);
            }
        }
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return this;
}

From source file:net.proest.librepilot.web.handler.ObjectHandler.java

public void handlePost(String target, Request baseRequest, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    BufferedReader br = request.getReader();
    String json = "";
    while (br.ready()) {
        json += br.readLine();/*  w  ww .j a va2  s. c o m*/
    }
    System.out.println(json);
    json = json.replaceFirst("json=", "");
    System.out.println(json);
    json = URLDecoder.decode(json, "utf-8");
    System.out.println(json);
    System.out.println();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode actualObj = mapper.readTree(json);
    out.println(actualObj.asText());
    out.println(mapper.toString());
}

From source file:org.eclipse.xtend.util.uml2ecore.Uml2EcoreXmiWriter.java

private void removeAbsoluteFileRefs(XmiWriterURIConverter uriConverter, Resource r, String filename) {
    try {//  w w w.  j  av  a 2s. c  o  m
        StringBuffer newFile = new StringBuffer();
        InputStream stream = uriConverter.createInputStream(r.getURI());
        BufferedReader br = new BufferedReader(new InputStreamReader(stream));
        while (br.ready()) {
            String s = br.readLine();
            s = s.replaceAll(filename + "#//", "#//");
            newFile.append(s + "\n");
        }
        br.close();
        stream.close();
        OutputStream s = uriConverter.createOutputStream(r.getURI());
        PrintStream ps = new PrintStream(s);
        ps.print(newFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.streams.twitter.test.TweetActivitySerDeTest.java

@Test
public void Tests() {
    InputStream is = TweetActivitySerDeTest.class.getResourceAsStream("/testtweets.txt");
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    try {/* www. ja va2 s.c o m*/
        while (br.ready()) {
            String line = br.readLine();
            if (!StringUtils.isEmpty(line)) {
                LOGGER.info("raw: {}", line);

                Class detected = TwitterEventClassifier.detectClass(line);

                Activity activity = twitterJsonActivitySerializer.deserialize(line);

                String activitystring = mapper.writeValueAsString(activity);

                LOGGER.info("activity: {}", activitystring);

                assertThat(activity, is(not(nullValue())));

                assertThat(activity.getId(), is(not(nullValue())));
                assertThat(activity.getActor(), is(not(nullValue())));
                assertThat(activity.getActor().getId(), is(not(nullValue())));
                assertThat(activity.getVerb(), is(not(nullValue())));
                assertThat(activity.getProvider(), is(not(nullValue())));

                if (detected == Tweet.class) {

                    assertEquals(activity.getVerb(), "post");

                    Tweet tweet = mapper.readValue(line, Tweet.class);

                    if (tweet.getEntities() != null && tweet.getEntities().getUrls() != null
                            && tweet.getEntities().getUrls().size() > 0) {

                        assertThat(activity.getLinks(), is(not(nullValue())));
                        assertEquals(tweet.getEntities().getUrls().size(), activity.getLinks().size());
                    }

                } else if (detected == Retweet.class) {

                    Retweet retweet = mapper.readValue(line, Retweet.class);

                    assertThat(retweet.getRetweetedStatus(), is(not(nullValue())));

                    assertEquals(activity.getVerb(), "share");

                    assertThat(activity.getObject(), is(not(nullValue())));
                    assertThat(activity.getObject().getObjectType(), is(not(nullValue())));
                    assertThat(activity.getObject().getObjectType(), is(not(nullValue())));

                    if (retweet.getRetweetedStatus().getEntities() != null
                            && retweet.getRetweetedStatus().getEntities().getUrls() != null
                            && retweet.getRetweetedStatus().getEntities().getUrls().size() > 0) {

                        assertThat(activity.getLinks(), is(not(nullValue())));
                        assertEquals(retweet.getRetweetedStatus().getEntities().getUrls().size(),
                                activity.getLinks().size());
                    }

                }

            }
        }
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:pl.sgorecki.facebook.marketing.ads.impl.FacebookAdsErrorHandler.java

private String readFully(InputStream in) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder sb = new StringBuilder();
    while (reader.ready()) {
        sb.append(reader.readLine());/*from   ww  w  .  ja v  a  2 s  .  c o m*/
    }
    return sb.toString();
}

From source file:di.uniba.it.tri.aan.AAN2file.java

private List<Paper> loadPaperList(File metadatafile, String paperdirname) throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(metadatafile));
    String id = null;/*w ww .  jav  a2  s  . c  o m*/
    String year = null;
    List<Paper> list = new ArrayList<>();
    while (reader.ready()) {
        String line = reader.readLine();
        if (line.startsWith("id = {")) {
            id = getValue(line);
        } else if (line.startsWith("year = {")) {
            year = getValue(line);
        }
        if (line.length() == 0) {
            if (id != null && year != null) {
                Paper paper = new Paper(id);
                paper.setYear(Integer.parseInt(year));
                paper.setFile(new File(paperdirname + "/" + id + ".txt"));
                list.add(paper);
            }

        }
    }
    return list;
}

From source file:ffx.potential.parsers.XYZFilter.java

/**
 * <p>//from   w w  w  .  j a  v a 2  s .c o m
 * readOnto</p>
 *
 * @param newFile a {@link java.io.File} object.
 * @param oldSystem a {@link ffx.potential.MolecularAssembly} object.
 * @return a boolean.
 */
public static boolean readOnto(File newFile, MolecularAssembly oldSystem) {
    if (newFile == null || !newFile.exists() || oldSystem == null) {
        return false;
    }
    try {
        FileReader fr = new FileReader(newFile);
        BufferedReader br = new BufferedReader(fr);
        String data = br.readLine();
        if (data == null) {
            return false;
        }
        String tokens[] = data.trim().split(" +");
        int num_atoms = Integer.parseInt(tokens[0]);
        if (num_atoms != oldSystem.getAtomList().size()) {
            return false;
        }
        double d[][] = new double[num_atoms][3];
        for (int i = 0; i < num_atoms; i++) {
            if (!br.ready()) {
                return false;
            }
            data = br.readLine();
            if (data == null) {
                logger.warning("Check atom " + (i + 1));
                return false;
            }
            tokens = data.trim().split(" +");
            if (tokens == null || tokens.length < 6) {
                logger.warning("Check atom " + (i + 1));
                return false;
            }
            d[i][0] = Double.parseDouble(tokens[2]);
            d[i][1] = Double.parseDouble(tokens[3]);
            d[i][2] = Double.parseDouble(tokens[4]);
        }
        ArrayList<Atom> atoms = oldSystem.getAtomList();
        for (Atom a : atoms) {
            int index = a.getXYZIndex() - 1;
            a.setXYZ(d[index]);
        }
        oldSystem.center();
        oldSystem.setFile(newFile);
        br.close();
        fr.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}