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:com.company.ComponentParser.java

public static Compo Parse(String url) throws Exception {
    InputStream inputStream = new URL(url).openStream();
    String content = IOUtils.toString(inputStream);

    Document document = Jsoup.parse(content);
    Element body = document.body();
    Elements elements = body.select(".grid");
    Compo compo = new Compo();

    Elements tds = elements.get(1).select("th"); //System.out.println(content);

    tds.forEach(element -> {/*from ww w .  j a v  a2 s .  c o m*/

        //  System.out.println(element.text());
        switch (element.text()) {
        case "License":
            compo.setLicense(element.nextElementSibling().text());
            break;
        case "Categories":
            compo.setCategories(element.nextElementSibling().text());
            break;
        case "HomePage":
            compo.setHomePage(element.nextElementSibling().select("a").text());
            break;
        case "Date":
            compo.setDate(element.nextElementSibling().text());
            break;
        case "Repository":
            compo.setRepository(element.nextElementSibling().text());
            break;
        case "Usages":
            compo.setUsage(element.nextElementSibling().text());
            break;
        }
    });

    return compo;
}

From source file:com.assertthat.selenium_shutterbug.utils.file.FileUtil.java

public static String getJsScript(String filePath) {
    try {/*from   ww w .j  a  v a  2s .  com*/
        return IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath));
    } catch (IOException e) {
        throw new UnableTakeSnapshotException("Unable to load JS script", e);
    }
}

From source file:javaapplication1.RTFTester.java

public static void doStuff() {
    try {//from  w  ww .  ja va  2s .c  o  m
        String content = IOUtils.toString(new FileInputStream("D:\\TemplateBuilder.rtf"));
        content = content.replaceAll("TAB_NUM", "9003");
        content = content.replaceAll("FULL_NAME", " ? ?");
        content = content.replaceAll("LOGIN", "NMoldabe");
        content = content.replaceAll("ACCEPT_DATE", "2015-09-21");
        IOUtils.write(content, new FileOutputStream("D:\\result.rtf"));

    } catch (FileNotFoundException ex) {
        Logger.getLogger(RTFTester.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RTFTester.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.jamesashepherd.sshproxyj.core.UtilsTest.java

/**
 * @since 1.0// w w w .ja  v  a  2s.  c o  m
 * @return
 * @throws IOException
 */
private static String stringFromResource(String resourcePath) throws IOException {
    InputStream is = UtilsTest.class.getResourceAsStream(resourcePath);
    return IOUtils.toString(is);
}

From source file:com.mightypocket.utils.ResourceHelper.java

public static String loadString(String name, ResourceMap resourceMap) {
    String result = null;/* w ww  .j a v  a  2 s.c o m*/

    InputStream is = null;
    try {
        is = AShot.class.getResourceAsStream("resources/" + name);
        result = IOUtils.toString(is);
        Set<String> keySet = resourceMap.keySet();
        for (String key : keySet) {
            String token = "${" + key + "}";
            if (result.contains(token)) {
                String value = resourceMap.getString(key);
                result = result.replace(token, value);
            }
        }
    } catch (Exception e) {
        //should never be a case
        logger.error("Cannot load resource", e);
    } finally {
        IOUtils.closeQuietly(is);
    }
    return result;
}

From source file:com.switchfly.compress.TestingUtil.java

public static String readFile(Class clazz, String resource) throws IOException {
    return IOUtils.toString(clazz.getResourceAsStream(resource));
}

From source file:com.gs.obevo.util.IOUtilsDA.java

public static String toString(InputStream input) {
    try {//  ww w .  j a va 2s  . co  m
        return IOUtils.toString(input);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:fi.mystes.synapse.mediator.util.TestUtil.java

public static String getResuorceAsString(String fileName) {
    try {//  w ww  . java 2s .c  o  m
        return IOUtils.toString(classpathResource(fileName));
    } catch (IOException e) {
        return null;
    }
}

From source file:ch.oakmountain.tpa.web.TpaPersistorUtils.java

public static void copyFromResourceToDir(String fileName, String outputDir) throws IOException {
    String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream(File.separator + fileName));
    FileUtils.writeStringToFile(new File(outputDir + File.separator + fileName), content);
}

From source file:inf2015jsonintroduction.FileReader.java

public static String loadFileIntoString(String filePath/*, String fileEncoding*/)
        throws FileNotFoundException, IOException {
    return IOUtils.toString(new FileInputStream(filePath)/*, fileEncoding*/);
}