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) throws IOException 

Source Link

Document

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

Usage

From source file:io.pcp.parfait.dxm.PcpClient.java

String getMetric(String metricName) throws Exception {
    Process exec = Runtime.getRuntime().exec("pmdumptext -s 1 -t 0.001 -r " + metricName);
    exec.waitFor();/*from w  w w .java 2s .  co m*/
    if (exec.exitValue() != 0) {
        throw new PcpFetchException(exec);
    }

    String result = IOUtils.toString(exec.getInputStream());
    Pattern pattern = Pattern.compile("\t(.*?)\n");
    Matcher matcher = pattern.matcher(result);
    if (matcher.find()) {
        return matcher.group(1);
    }
    throw new PcpFetchException("Could not find metric in the output: " + result);
}

From source file:com.opencarte.db.TaxisParser.java

public TaxisParser(String fileName) {
    super(fileName);
    try {//from   w ww .  j av a  2  s.  com
        this.myFileContent = IOUtils.toString(new URL(fileName).openStream());
        myBuilder = new GsonBuilder();
    } catch (IOException ex) {
        System.out.println(ex);
        //Logger.getLogger(Parser.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.opencarte.db.VotesParser.java

public VotesParser(String fileName) {
    super(fileName);
    try {/*from ww w. j a v a  2  s. co m*/
        this.myFileContent = IOUtils.toString(new URL(fileName).openStream());
        myBuilder = new GsonBuilder();
    } catch (IOException ex) {
        System.out.println(ex);
        //Logger.getLogger(Parser.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.allogy.couch.importers.command.BufferedImportCommand.java

public BufferedImportCommand(ImportCommand innerImportCommand) throws IOException {
    this.innerImportCommand = innerImportCommand;
    dataString = IOUtils.toString(innerImportCommand.getDataStream());
}

From source file:com.droitfintech.licensing.ObfuscatedLicenseProvider.java

public License retrieveLicense() {

    License answer;// ww  w. j  a  v a2s .  c  om

    InputStream stream = FilesystemDataLoader.loadFileAsInputStream(filename);

    String obfuscated;
    try {
        obfuscated = IOUtils.toString(stream);
    } catch (IOException e) {
        throw new DroitException("Unable to convert stream to string for file '" + filename + "'", e);
    }

    try {
        answer = decodeObfuscatedLicense(obfuscated);
    } catch (Exception e) {
        throw new DroitException("Unable to deserialize '" + filename + "'", e);
    }

    return answer;
}

From source file:com.nextdoor.bender.handler.dynamodb.DynamodbHandlerTest.java

@Override
public DynamodbEvent getTestEvent() throws Exception {
    String json = IOUtils.toString(
            new InputStreamReader(this.getClass().getResourceAsStream("dynamodb_records.json"), "UTF-8"));
    return DynamodbEventDeserializer.deserialize(json);
}

From source file:b2s.idea.mavenize.TestJarFilenamePool.java

public TestJarFilenamePool() {
    InputStream input = null;//from   www.j  av a2 s. c o m
    try {
        input = Thread.currentThread().getContextClassLoader().getResourceAsStream("intellij-jars.txt");
        filenamePool = new ArrayList(Arrays.asList(IOUtils.toString(input).split("\r\n|\n")));
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(input);
    }
}

From source file:com.charandeepmatta.database.di.Schema.java

private static void updateSqlTo(final JdbcTemplate jdbc, final InputStream inputStream) throws IOException {
    String sqlFileAsString = IOUtils.toString(inputStream);
    jdbc.update(sqlFileAsString);/*from   ww  w . ja  v a2  s .  co  m*/
}

From source file:be.roots.taconic.pricingguide.util.HttpUtil.java

public static String readString(String urlAsString, String userName, String password) {

    try {/* www .  ja  v a 2s  .com*/
        final HttpURLConnection con = getInputStreamFor(urlAsString, userName, password);
        final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        final String response = IOUtils.toString(in);
        IOUtils.closeQuietly(in);
        return response;
    } catch (IOException e) {
        LOGGER.error(e.getLocalizedMessage(), e);
    }
    return null;

}

From source file:com.collective.celos.ci.testing.fixtures.convert.UpperCaseStringFixFileConverter.java

@Override
public FixFile convert(TestRun tr, FixFile ff) throws IOException {
    String newContent = IOUtils.toString(ff.getContent()).toUpperCase();
    return new FixFile(IOUtils.toInputStream(newContent));
}