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

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

Introduction

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

Prototype

public static String toString(Readable r) throws IOException 

Source Link

Document

Reads all characters from a Readable object into a String .

Usage

From source file:com.s13g.FileUtil.java

public static String readAsString(String filename) throws IOException {
    FileInputStream inputStream = new FileInputStream(filename);
    return CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
}

From source file:com.google.javascript.jscomp.ResourceLoader.java

static String loadTextResource(Class<?> clazz, String path) {
    try {//from  w w  w.  j  av a  2  s  . com
        return CharStreams.toString(new InputStreamReader(clazz.getResourceAsStream(path), UTF_8));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.example.authentication.utils.Util.java

public static String readResource(String resourceFile) {
    try (InputStreamReader reader = new InputStreamReader(
            GetViewRequestExecutor.class.getResourceAsStream(resourceFile), Charsets.UTF_8)) {
        return CharStreams.toString(reader);
    } catch (IOException e) {
        throw new RuntimeException("Could not find resource " + resourceFile, e);
    }/* w  w w  .j a  v a  2 s.c  o  m*/
}

From source file:com.google.javascript.jscomp.resources.ResourceLoader.java

public static String loadTextResource(Class<?> clazz, String path) {
    try {//from  w  w w. j av a  2 s.  c o m
        return CharStreams.toString(new InputStreamReader(clazz.getResourceAsStream(path), UTF_8));
    } catch (NullPointerException e) {
        if (!resourceExists(clazz, path)) {
            throw new RuntimeException("No such resource: " + path);
        }
        throw e;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.wrmsr.neurosis.util.Files.java

public static String readFile(String path) throws IOException {
    try (BufferedReader br = java.nio.file.Files.newBufferedReader(FileSystems.getDefault().getPath(path),
            StandardCharsets.UTF_8)) {
        return CharStreams.toString(br);
    }//from w  w w.  j  a  va 2s .  c o  m
}

From source file:org.trimou.util.IOUtils.java

/**
 * The reader is closed right after the input is read.
 *
 * @param input//ww w .java  2s.c  o m
 * @return the contents of a reader as a string
 * @throws IOException
 */
public static String toString(final Reader input) throws IOException {
    Checker.checkArgumentNotNull(input);
    try {
        return CharStreams.toString(input);
    } finally {
        // Input cannot be null
        input.close();
    }
}

From source file:com.google.cloud.tools.maven.it.util.UrlUtils.java

/**
 * If the response code is 200, returns the content at the URL. Otherwise, returns null.
 */// w  ww.  ja v  a  2  s  .  c  om
public static String getUrlContent(String url) {
    try {
        HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
        int responseCode = urlConnection.getResponseCode();
        if (responseCode == 200) {
            return CharStreams.toString(new InputStreamReader(urlConnection.getInputStream()));
        }
    } catch (IOException e) {
    }
    return null;
}

From source file:com.galois.fiveui.Utils.java

public static String readStream(final InputStream stream) throws IOException {
    return CharStreams.toString(new InputStreamReader(stream));
}

From source file:dollar.docs.ParseDocs.java

private static void parseDoc(@NotNull String page, @NotNull File outDir) throws IOException {
    outDir.mkdirs();// w  w  w .j av a 2  s  .c o m
    String source = CharStreams
            .toString(new InputStreamReader(ParseDocs.class.getResourceAsStream("/pages/" + page + ".md")));
    String toParse;
    if (source.startsWith("#!")) {
        toParse = "\n" + source.substring(source.indexOf("\n"));
    } else {
        toParse = source;
    }
    new DollarParserImpl(new ParserOptions()).parseMarkdown(toParse);
    PegDownProcessor pegDownProcessor = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS);
    String result = pegDownProcessor.markdownToHtml(toParse);
    Files.write(new File(outDir, page + ".html").toPath(), result.getBytes());
    Files.write(new File(outDir, page + ".md").toPath(), toParse.getBytes());
    System.exit(0);
}

From source file:pl.nalazek.githubsearch.util.TextToString.java

public static String read(String filename, Charset charset) throws IOException {
    FileInputStream inputStream = new FileInputStream(filename);
    return CharStreams.toString(new InputStreamReader(inputStream, charset));
}