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.hurence.logisland.BannerLoader.java

public static final String loadBanner() throws IOException {
    try (InputStream is = BannerLoader.class.getClassLoader().getResourceAsStream("banner.txt")) {
        return IOUtils.toString(is);
    }//from  w ww .  ja  v  a2 s  .com
}

From source file:com.demonwav.mcdev.platform.forge.version.ForgeVersion.java

@Nullable
public static ForgeVersion downloadData() {
    try (InputStream in = new URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/json")
            .openStream()) {//  ww  w  .j a  v a2  s.  c  o m
        final String text = IOUtils.toString(in);

        final Map map = new Gson().fromJson(text, Map.class);
        final ForgeVersion version = new ForgeVersion();
        version.map = map;
        return version;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:latexstudio.editor.files.FileService.java

public static String readFromFile(String filename) {
    try (FileReader reader = new FileReader(filename)) {
        return IOUtils.toString(reader);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);/*from   w  w  w  . j a va  2 s.  c  om*/
    }

    return null;
}

From source file:com.nomsic.randb.test.TestUtils.java

public static String getFileAsString(File file) throws FileNotFoundException, IOException {
    FileReader fileReader = new FileReader(file);
    String indexString = IOUtils.toString(fileReader);
    fileReader.close();/*from   ww  w  .ja va 2 s .c  o  m*/
    return indexString;
}

From source file:com.netflix.spinnaker.halyard.core.resource.v1.JarResourceReader.java

static String readResource(String path) {
    InputStream contents = JarResourceReader.class.getResourceAsStream(path);

    if (contents == null) {
        throw new IllegalArgumentException("Path " + path + " could not be found in the JAR");
    }/* ww w.ja  v a2 s. c  o  m*/

    try {
        return IOUtils.toString(contents);
    } catch (IOException e) {
        throw new RuntimeException("Path " + path + " could not be opened", e);
    }
}

From source file:com.cognifide.aet.communication.api.metadata.SuiteReaderHelper.java

static Suite readSuiteFromFile(String resource, ClassLoader classLoader) throws IOException {
    String json = IOUtils.toString(classLoader.getResourceAsStream(resource));
    return GSON.fromJson(json, new TypeToken<Suite>() {
    }.getType());// w w  w. ja  va  2s  .c  o m
}

From source file:com.mightypocket.ashot.UpdateChecker.java

public static String check() {
    String version = null;/*from w ww.ja  va 2  s  .co  m*/
    try {
        URL url = new URL(UPDATE_URL);
        Object content = url.getContent();
        if (content instanceof InputStream) {
            String text = IOUtils.toString((InputStream) content);
            int st = text.indexOf(VERSION);
            if (st >= 0) {
                st += VERSION.length();
                int end = text.indexOf("]", st);
                version = text.substring(st, end);
            }
        }
    } catch (Exception ex) {
        logger.error("Cannot check for updates.", ex);
    }

    return version;
}

From source file:common.DBTestUtil.java

public static void initDB() throws IOException, SQLException {
    String query = "";
    FileInputStream inputStream = new FileInputStream(TEST_DATA_FILE);

    try {/*from   w  w  w.  j av  a  2  s . c o  m*/
        query = IOUtils.toString(inputStream);
    } finally {
        inputStream.close();
    }

    Connection connection = DB.getConnection();

    try {
        Statement statement = connection.createStatement();
        statement.execute(query);
    } finally {
        connection.close();
    }
}

From source file:com.akjava.wiki.client.keyword.KeyWordUtils.java

public static Keyword[] loadCsvKeyWord(Reader reader) {
    List<Keyword> list = new ArrayList<Keyword>();
    String text;/*from  ww  w .j  a  v  a 2  s  . com*/
    try {
        text = IOUtils.toString(reader);
        String line[] = text.split(SystemUtils.LINE_SEPARATOR);
        for (int i = 0; i < line.length; i++) {
            String word[] = line[i].split(",");
            if (word.length > 1) {
                Keyword key = new Keyword(word[0], word[1]);
                if (word.length > 2) {
                    key.setIcon(word[2].trim());
                }
                list.add(key);
            } else if (word.length == 1) {
                String w = word[0];
                if (!w.startsWith("<") && !w.isEmpty()) {//ignore tag & empty
                    Keyword key = new Keyword(w, "");
                    list.add(key);
                }

            }

        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Keyword[] keywords = (Keyword[]) list.toArray(new Keyword[list.size()]);
    Arrays.sort(keywords);

    return keywords;
}

From source file:io.mandrel.MockMvcUtils.java

public static void print(ResultActions result) throws IOException, UnsupportedEncodingException {
    System.err.println(IOUtils.toString(result.andReturn().getRequest().getInputStream()));
    CollectionUtils.toIterator(result.andReturn().getRequest().getHeaderNames())
            .forEachRemaining(h -> System.err.println(h + ":" + result.andReturn().getRequest().getHeader(h)));

    System.err.println(result.andReturn().getResponse().getContentAsString());
    result.andReturn().getResponse().getHeaderNames()
            .forEach(h -> System.err.println(h + ":" + result.andReturn().getResponse().getHeader(h)));
}