Example usage for com.google.common.io CharStreams readLines

List of usage examples for com.google.common.io CharStreams readLines

Introduction

In this page you can find the example usage for com.google.common.io CharStreams readLines.

Prototype

public static List<String> readLines(Readable r) throws IOException 

Source Link

Document

Reads all of the lines from a Readable object.

Usage

From source file:org.kurento.test.internal.CheckNodes.java

public void check() throws IOException {
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("node-list.txt");
    List<String> nodeList = CharStreams.readLines(new InputStreamReader(inputStream, Charsets.UTF_8));

    List<String> nodesWithoutXvfb = new ArrayList<String>();
    List<String> nodesWithException = new ArrayList<String>();
    List<String> nodesDown = new ArrayList<String>();
    List<String> nodesOk = new ArrayList<String>();

    for (String node : nodeList) {
        if (SshConnection.ping(node)) {

            SshConnection remoteHost = new SshConnection(node);
            try {
                remoteHost.start();//from  w  w  w.j  a v a 2 s  .  c  o m
                int xvfb = remoteHost.runAndWaitCommand("xvfb-run");
                if (xvfb != 2) {
                    nodesWithoutXvfb.add(node);
                } else {
                    nodesOk.add(node);
                }
                log.debug("{} {}", node, xvfb);
            } catch (Exception e) {
                log.error("Exception in node {} : {}", node, e.getClass());
                nodesWithException.add(node);
            } finally {
                remoteHost.stop();
            }
        } else {
            log.error("Node down {}", node);
            nodesDown.add(node);
        }
    }

    log.debug("Nodes Ok: {} {}", nodesOk.size(), nodesOk);
    log.debug("Nodes without Xvfb: {} {}", nodesWithoutXvfb.size(), nodesWithoutXvfb);
    log.debug("Nodes with exception: {} {}", nodesWithException.size(), nodesWithException);
    log.debug("Nodes down: {} {}", nodesDown.size(), nodesDown);
}

From source file:org.terasology.assets.test.stubs.book.BookFileFormat.java

@Override
public BookData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    try (BufferedReader reader = new BufferedReader(
            new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8))) {
        return new BookData(CharStreams.readLines(reader));
    }//w  w  w. j ava 2s  .c  o m
}

From source file:com.ninja_squad.core.jsp.JspFunctions.java

/**
 * Transforms all the newlines into <code>&lt;br/&gt;</code>, in order for multi-line text
 * to be displayed into an HTML page. Each line of text is also XML-escaped. <br/>
 * If a null string is passed as argument, an empty string is returned.
 * @param input the string to transform/* w  w  w.  j  a v a 2  s. com*/
 * @return the transformed string.
 */
public static String nlToBr(@Nullable String input) {
    if (input == null) {
        return "";
    }

    try {
        List<String> lines = CharStreams.readLines(new StringReader(input));
        return Joiner.on("<br/>").join(Iterables.transform(lines, ESCAPE_XML));
    } catch (IOException e) {
        throw new ShouldNeverHappenException(e);
    }
}

From source file:eu.numberfour.n4js.SmokeTestWriter.java

@Override
public Script parse(InputStream in, URI uriToUse, Map<?, ?> options, ResourceSet resourceSet) {
    if (active) {
        if (in instanceof LazyStringInputStream) {
            try {
                String string = ((LazyStringInputStream) in).getString();
                if (string.length() < 1000 && seen.add(string)) {
                    List<String> lines = CharStreams.readLines(new StringReader(string));
                    if (lines.size() < 50) {
                        System.out.println("\t@Test");
                        System.out.format("\tdef void test_%04d() {", counter++);
                        System.out.println();
                        System.out.println("\t\t'''");
                        for (String s : lines) {
                            System.out.print("\t\t\t");
                            System.out.println(s);
                        }/*from w  w  w . j ava  2s  . co  m*/
                        System.out.println("\t\t'''.assertNoException");
                        System.out.println("\t}");
                        System.out.println();
                    }
                }
            } catch (IOException e) {
                // ignore
            }
        }
    }
    return super.parse(in, uriToUse, options, resourceSet);
}

From source file:com.ibm.katheder.map.generation.MapGeneratorFactory.java

private static List<String> loadResource(final String resourceName) throws IOException {
    final ClassLoader cl = ClassLoader.getSystemClassLoader();
    final InputStream inputStream = cl.getResourceAsStream(resourceName);
    return CharStreams.readLines(new InputStreamReader(inputStream, CHARSET));
}

From source file:org.jetbrains.jet.repl.ReplSessionTestFile.java

public static ReplSessionTestFile load(@NotNull File file) {
    try {/*from  w w  w .j av a  2 s.c o  m*/
        FileInputStream inputStream = new FileInputStream(file);
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
            List<String> lines = CharStreams.readLines(reader);
            return load(new SimpleLinesParser(lines));
        } finally {
            inputStream.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.kurento.test.internal.KillAllProcesses.java

public void killAll() throws IOException {

    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("node-list.txt");
    List<String> nodeList = CharStreams.readLines(new InputStreamReader(inputStream, Charsets.UTF_8));

    for (String node : nodeList) {
        if (SshConnection.ping(node)) {
            try {
                SshConnection remoteHost = new SshConnection(node);
                remoteHost.start();//from  w w  w  .  j  a v  a 2  s  . co  m
                remoteHost.execCommand("kill", "-9", "-1");
            } catch (Throwable e) {
                e.printStackTrace();
            }
        } else {
            log.error("Node down {}", node);
        }
    }
}

From source file:org.terasology.assets.test.stubs.text.TextFileFormat.java

@Override
public TextData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
    TextData data = new TextData();
    if (!inputs.isEmpty()) {
        try (InputStreamReader reader = new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8)) {
            data.setValue(Joiner.on('\n').join(CharStreams.readLines(reader)));
        }//from   w w  w . j av a 2  s  .c  o  m
    }
    return data;
}

From source file:org.eclipse.che.plugin.docker.client.DockerfileParser.java

/** Parse content of Dockerfile that is represented by String value. */
public static Dockerfile parse(String contentOfDockerFile) throws DockerFileException {
    try {/* w  ww.ja va2 s . c  o m*/
        return parse(CharStreams.readLines(CharSource.wrap(contentOfDockerFile).openStream()));
    } catch (IOException e) {
        throw new DockerFileException("Error happened parsing the Docker file:" + e.getMessage(), e);
    }
}

From source file:org.caleydo.data.importer.tcga.model.ClinicalMapping.java

/**
 * @param string//from   w ww  .  j  av a  2  s  .com
 * @return
 */
private static ListMultimap<String, CategoryProperty<String>> parseProperties(String fileName) {
    try (InputStreamReader r = new InputStreamReader(
            ClinicalMapping.class.getResourceAsStream("/resources/" + fileName))) {
        List<String> lines = CharStreams.readLines(r);
        lines.remove(0);
        ListMultimap<String, CategoryProperty<String>> result = ArrayListMultimap.create();
        for (String line : lines) {
            String[] ls = line.split("\t");
            String key = ls[0];
            String name = ls[1];
            String label = ls.length > 2 ? ls[2] : name;
            Color color = ls.length > 3 ? new Color(ls[3]) : null;
            result.put(key, new CategoryProperty<String>(name, label, color));
        }
        return result;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ImmutableListMultimap.of();
}