Example usage for com.google.common.io Resources toString

List of usage examples for com.google.common.io Resources toString

Introduction

In this page you can find the example usage for com.google.common.io Resources toString.

Prototype

public static String toString(URL url, Charset charset) throws IOException 

Source Link

Document

Reads all characters from a URL into a String , using the given character set.

Usage

From source file:com.test.http.utils.ViewUtils.java

public static String render(String name) throws IOException {
    return Resources.toString(Resources.getResource(PREFIX + name + SUFFIX), Charsets.UTF_8);
}

From source file:org.apache.mahout.Version.java

public static String versionFromResource() throws IOException {
    return Resources.toString(Resources.getResource("version"), Charsets.UTF_8);
}

From source file:br.com.objectos.testing.MoreAsserts.java

public static String toString(String name) {
    try {/*  ww w  .j  a  va  2 s  . c o m*/
        URL url = Resources.getResource(MoreAsserts.class, name);
        return Resources.toString(url, Charsets.UTF_8);
    } catch (IOException e) {
        return "";
    }
}

From source file:org.sonar.plugins.checkstyle.CheckstyleTestUtils.java

public static String getResourceContent(String path) {
    try {/*from  w w  w  .  jav a 2 s  . c  o m*/
        return Resources.toString(Resources.getResource(CheckstyleTestUtils.class, path), Charsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not load resource " + path, e);
    }
}

From source file:net.chris54721.infinitycubed.Updater.java

public static void checkUpdates() {
    try {/*from ww  w.  j a  va  2s  .co  m*/
        LogHelper.info("Checking for launcher updates");
        String version = Resources.toString(new URL(Reference.FILES_URL + "version.cfg"), Charsets.UTF_8);
        if (!version.equalsIgnoreCase(Launcher.getVersion()))
            downloadUpdate(version);
    } catch (Exception e) {
        LogHelper.error("Failed checking for launcher updates", e);
    }
}

From source file:mongis.utils.TextFileUtils.java

public static String readFileFromJar(String url, Class<?> clazz) throws IOException {
    System.out.println(url);//from  w w w .ja  v  a  2 s.  c o  m
    return Resources.toString(clazz.getResource(url), Charset.forName("UTF-8"));
}

From source file:com.urswolfer.intellij.plugin.gerrit.util.Version.java

private static String parseVersionFromFile(URL url) throws IOException {
    String text = Resources.toString(url, Charsets.UTF_8);

    Pattern versionTagPattern = Pattern.compile(".*?<version>(.+?)</version>");
    Matcher matcher = versionTagPattern.matcher(text);
    if (matcher.find()) {
        return matcher.group(1);
    } else {//from w  ww  . jav a  2 s . c o m
        return "<unknown>";
    }
}

From source file:com.streamsets.pipeline.stage.origin.mysql.Utils.java

public static void runInitScript(String initScriptPath, DataSource dataSource) throws SQLException {
    try (Connection conn = dataSource.getConnection()) {
        try {/* w  w  w .  ja  v  a  2 s . co  m*/
            URL resource = Resources.getResource(initScriptPath);
            String sql = Resources.toString(resource, Charsets.UTF_8);
            ScriptUtils.executeSqlScript(conn, initScriptPath, sql);
            conn.commit();
            conn.close();
        } catch (IOException | IllegalArgumentException e) {
            LOGGER.warn("Could not load classpath init script: {}", initScriptPath);
            throw new SQLException("Could not load classpath init script: " + initScriptPath, e);
        } catch (ScriptException e) {
            LOGGER.error("Error while executing init script: {}", initScriptPath, e);
            throw new SQLException("Error while executing init script: " + initScriptPath, e);
        }
    }
}

From source file:net.fabricmc.installer.util.Translator.java

public static void load(Locale locale, HashMap<String, String> map) throws IOException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (!isValid(locale)) {
        return;//from ww  w .jav  a 2 s. co  m
    }
    String string = Resources.toString(
            classLoader.getResource(locale.getLanguage() + "_" + locale.getCountry() + ".lang"),
            StandardCharsets.UTF_8);
    String[] lines = string.split(System.getProperty("line.separator"));
    for (String line : lines) {
        if (!line.startsWith("#") && line.contains("=")) {
            String[] split = line.split("=");
            map.put(split[0], split[1]);
        }
    }

}

From source file:com.cloudera.whirr.cm.Utils.java

public static URL urlForURI(String inputStr) {
    try {/*w  ww . j a v  a2 s . co m*/
        if (inputStr == null) {
            return null;
        }
        URI input = new URI(inputStr).normalize();
        if (input.getScheme() != null && input.getScheme().equals("classpath")) {
            return Utils.class.getResource(input.getPath());
        }
        if (Resources.toString(input.toURL(), Charsets.UTF_8) != null) {
            return input.toURL();
        } else {
            return null;
        }
    } catch (IOException e) {
        // Swallow the exception for now and just return null - this could probably be better.
        return null;
    } catch (URISyntaxException e) {
        // Swallow the exception for now and just return null - this could probably be better.
        return null;
    }
}