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

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

Introduction

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

Prototype

public static String toString(byte[] input, String encoding) throws IOException 

Source Link

Document

Get the contents of a byte[] as a String using the specified character encoding.

Usage

From source file:com.civis.utils.opennlp.models.BaseModelTest.java

protected static String getTextExample(String fileName) {
    String content = "";
    try (InputStream inputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream(fileName)) {
        content = IOUtils.toString(inputStream, "UTF-8");
        inputStream.close();// w w  w.ja v  a  2s . com
    } catch (IOException e) {
        Assert.fail();
    }

    return content;
}

From source file:com.yahoo.yqlplus.example.apis.Programs.java

public static void compilePrograms() throws IOException {
    String weatherProgram = IOUtils.toString(Programs.class.getResourceAsStream("/programs/weather.program"),
            "UTF-8");
    Injector injector = Guice.createInjector(new SourceModule());
    YQLPlusCompiler compiler = injector.getInstance(YQLPlusCompiler.class);
    try {/*from  w  ww .  j av  a 2 s .  c o m*/
        programMap.put("/weather", compiler.compile(weatherProgram));
    } catch (RecognitionException | IOException e) {
        throw new ProgramCompileException("Compiling program: " + weatherProgram + " failed ", e);
    }
}

From source file:io.bitgrillr.gocddockerexecplugin.SystemHelper.java

static String getSystemUid() throws IOException, InterruptedException {
    Process id = Runtime.getRuntime().exec(new String[] { "bash", "-c", "echo \"$(id -u):$(id -g)\"" });
    id.waitFor();/*ww w  . j  av  a  2s.c o  m*/
    return StringUtils.chomp(IOUtils.toString(id.getInputStream(), StandardCharsets.UTF_8));
}

From source file:br.gov.lexml.parser.documentoarticulado.TestUtil.java

public static String sampleText(String resourceName) {
    try {/*ww w  .j  a  v a 2s .c o m*/
        InputStream input = new BOMInputStream(TestUtil.class.getResourceAsStream(resourceName));
        try {
            return IOUtils.toString(input, ENCODING);
        } finally {
            input.close();
        }
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:ca.uhn.fhir.jpa.dao.GZipUtil.java

public static String decompress(byte[] theResource) {
    GZIPInputStream is;/*w w  w  .  j a va  2s.  co m*/
    try {
        is = new GZIPInputStream(new ByteArrayInputStream(theResource));
        return IOUtils.toString(is, "UTF-8");
    } catch (IOException e) {
        throw new DataFormatException("Failed to decompress contents", e);
    }
}

From source file:bookstore.BookUnmarshaller.java

public static Book[] BooksFromCsv(File file) {
    InputStream in = null;/* ww  w.ja v  a  2s  .c om*/
    Book[] books;
    try {
        in = FileUtils.openInputStream(file);
        books = BooksFromString(IOUtils.toString(in, Charset.forName("utf-8")));
    } catch (IOException | ParseException | NumberFormatException e) {
        return null;
    } finally {
        IOUtils.closeQuietly(in);
    }
    return books;
}

From source file:cd.go.notification.gitter.utils.Util.java

public static String readResource(String resourceFile) {
    try (InputStream reader = GetViewRequestExecutor.class.getResourceAsStream(resourceFile)) {
        return IOUtils.toString(reader, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException("Could not find resource " + resourceFile, e);
    }/*from  w w w  .j  ava  2s . c om*/
}

From source file:de.ocarthon.core.utility.GzipCompression.java

public static String decompress(InputStream inputStream) throws IOException {
    GZIPInputStream gis = null;// w  w  w  . j  a va  2 s.  c  o  m
    String json;

    try {
        gis = new GZIPInputStream(inputStream);
        json = IOUtils.toString(gis, "UTF-8");
    } finally {
        IOUtils.closeQuietly(gis);
    }

    return json;
}

From source file:de.micromata.genome.util.runtime.GroovyUtils.java

/**
 * Convert to string./*  w  ww.j  a  v  a2 s .c o  m*/
 *
 * @param is the is
 * @return the string
 */
public static String convertToString(InputStream is) {
    try {
        return IOUtils.toString(is, StandardCharsets.UTF_8.name());
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.datastax.sparql.ResourceHelper.java

public static String loadQuery(final String prefix, final int number) throws IOException {
    final String path = "/queries/" + prefix + number + ".sparql";
    final InputStream stream = ResourceHelper.class.getResourceAsStream(path);
    return IOUtils.toString(stream, "UTF-8");
}