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:org.openehr.designer.io.TemplateDeserializer.java

public static List<Archetype> deserialize(InputStream adltStream) throws IOException {
    try (Reader r = new BomSupportingReader(adltStream, Charsets.UTF_8)) {
        String adltContents = CharStreams.toString(r);
        return deserialize(adltContents);
    }/*  w  w  w  . jav  a  2  s.  c  om*/
}

From source file:org.jboss.seam.mail.util.MailTestUtil.java

public static String getStringContent(BodyPart bodyPart) throws IOException, MessagingException {
    return CharStreams.toString(new InputStreamReader(bodyPart.getInputStream()));
}

From source file:org.retrostore.ui.Template.java

public static Template fromFile(String filename) throws IOException {
    // TODO: need to cache file contents.
    InputStream fileStream = new FileInputStream(new File(filename));
    return new Template(CharStreams.toString(new InputStreamReader(fileStream, Charsets.UTF_8)));
}

From source file:com.github.sebhoss.doxia.AbstractWikitextParser.java

private static String readMarkupContent(final Reader reader) throws ParseException {
    try (Reader autoClosedReader = reader) {
        return Nullsafe.nullsafe(CharStreams.toString(Nullsafe.nullsafe(autoClosedReader)));
    } catch (final IOException exception) {
        throw new ParseException("Cannot read input", exception);
    }//from w w  w. j a va 2s.  c o m
}

From source file:com.atypon.wayf.integration.HttpTestUtil.java

protected static String getFileAsString(String path) {
    try {/* ww w. j  a v  a2s .c om*/
        return CharStreams.toString(new InputStreamReader(
                BaseHttpTest.class.getClassLoader().getResourceAsStream(path), Charsets.UTF_8));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.kurento.kmf.test.Shell.java

public static String runAndWait(final String... command) {
    log.debug("Running command on the shell: {}", Arrays.toString(command));

    Process p;//from  ww  w .j  ava  2s.  c  o m
    try {
        p = new ProcessBuilder(command).redirectErrorStream(true).start();

        String output = CharStreams.toString(new InputStreamReader(p.getInputStream(), "UTF-8"));

        return output;

    } catch (IOException e) {
        throw new KurentoException("Exception executing command on the shell: " + Arrays.toString(command), e);
    }
}

From source file:com.mdrsolutions.external.xml.XmlCalls.java

public static final String getXml(String filePath, boolean notClassPath) {

    String xml = "";
    InputStream is;//from   ww  w .j  a  v a  2  s . c  o  m

    if (!notClassPath) {
        return getXml(filePath);
    }

    try {
        File f = new File(filePath);
        is = new FileInputStream(f);
        xml = CharStreams.toString(new InputStreamReader(is));
        if (null == xml || xml.isEmpty()) {

            Closeables.closeQuietly(is);
            throw new IOException("File path to SQL file could not be read!");
        } else {
            Closeables.closeQuietly(is);
            return xml;
        }
    } catch (IOException ex) {
        logger.error("Could not read the sql file specified!", ex);
    }
    return xml;
}

From source file:org.opendaylight.protocol.util.PCEPHexDumpParser.java

public static List<byte[]> parseMessages(final InputStream is) throws IOException {
    Preconditions.checkNotNull(is);/*  w ww.  j  a  va  2s . c o m*/
    try (InputStreamReader isr = new InputStreamReader(is, "UTF-8")) {
        return parseMessages(CharStreams.toString(isr));
    }
}

From source file:at.plechinger.scrapeql.cli.ScrapeQLShell.java

public ScrapeQLShell(String[] args) {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
        Query query = parser.parse(CharStreams.toString(reader));

        Map<String, Object> output = query.execute();
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.INDENT_OUTPUT);

        String outputString = mapper.writeValueAsString(output);

        System.out.println(outputString);

    } catch (Throwable e) {
        System.out.println(e.getMessage());
    }/*  ww w  . j  a v  a  2  s  .co m*/
}

From source file:gmusic.api.comm.Util.java

public static String toString(final InputStream is, final Charset cs) throws IOException {
    Closeable closeMe = is;//from   w w  w. jav a  2  s  .c o m
    try {
        final InputStreamReader isr = new InputStreamReader(is, cs);
        closeMe = isr;
        return CharStreams.toString(isr);
    } finally {
        Closeables.close(closeMe, true);
    }
}