List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
From source file:com.mgmtp.perfload.loadprofiles.ui.AppModule.java
@Override protected void configure() { bind(File.class).annotatedWith(ConfigDir.class).toInstance(new File(baseDir, "config")); bind(File.class).annotatedWith(SettingsDir.class).toInstance(new File(baseDir, "settings")); try {/*from ww w .jav a 2 s. c o m*/ String appVersion = Resources.toString(getResource("com/mgmtp/perfload/loadprofiles/version.txt"), Charsets.UTF_8); bindConstant().annotatedWith(AppVersion.class).to(appVersion); } catch (IOException ex) { addError("Could not read app version from classpath"); } bind(AppFrame.class); bind(LoadProfileConfig.class); bind(LoadProfilesController.class); bind(ExceptionHandler.class); MethodInterceptor methodInterceptor = new MethodInterceptor() { @Inject ExceptionHandler exceptionHandler; @Override public Object invoke(final MethodInvocation invocation) throws Throwable { AppFrame frame = (AppFrame) invocation.getThis(); Cursor oldCursor = frame.getCursor(); try { frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); return invocation.proceed(); } catch (Throwable th) { exceptionHandler.handle(th); return null; } finally { frame.setCursor(oldCursor); } } }; requestInjection(methodInterceptor); bindInterceptor(Matchers.subclassesOf(AppFrame.class), Matchers.annotatedWith(Subscribe.class), methodInterceptor); }
From source file:org.isisaddons.module.docx.dom.IoHelper.java
public String asString(final String fileName) throws IOException { final URL fileUrl = asUrl(fileName); return Resources.toString(fileUrl, Charset.forName("UTF-8")); }
From source file:eu.seaclouds.platform.planner.core.resolver.DeployerTypesResolver.java
public DeployerTypesResolver(URL mappingFileUrl) throws IOException { mapping = YamlParser.load(Resources.toString(mappingFileUrl, Charsets.UTF_8)); initTypesMapping(); }
From source file:eu.seaclouds.platform.planner.core.DeployerTypesResolver.java
public DeployerTypesResolver(URL mappingFileUrl) throws IOException { Yaml yml = new Yaml(); mapping = (Map<String, Object>) yml.load(Resources.toString(mappingFileUrl, Charsets.UTF_8)); initTypesMapping();/*from www. ja v a2 s . c o m*/ }
From source file:ratpack.groovy.launch.GroovyVersionChecker.java
@Nullable private static String retrieveMinimumGroovyVersion() throws IOException { URL resource = GroovyVersionChecker.class.getClassLoader() .getResource("ratpack/minimum-groovy-version.txt"); return resource == null ? null : Resources.toString(resource, Charsets.UTF_8); }
From source file:org.glowroot.ui.IndexHtmlHttpService.java
@Override public CommonResponse handleRequest(CommonRequest request, Authentication authentication) throws Exception { URL url = IndexHtmlHttpService.class.getResource("/org/glowroot/ui/app-dist/index.html"); String indexHtml = Resources.toString(checkNotNull(url), UTF_8); String layout = layoutService.getLayoutJson(authentication); String contextPath = request.getContextPath(); String baseHref = contextPath.equals("/") ? "/" : contextPath + "/"; indexHtml = indexHtml.replace("<base href=\"/\">", "<base href=\"" + baseHref + "\"><script>var layout=" + layout + ";var contextPath='" + contextPath + "'</script>"); // this is to work around an issue with IE10-11 (IE9 is OK) // (even without reverse proxy/non-root base href) // IE doesn't use the base href when loading the favicon indexHtml = indexHtml.replaceFirst("<link rel=\"shortcut icon\" href=\"favicon\\.([0-9a-f]+)\\.ico\">", "<script>document.write('<link rel=\"shortcut icon\" href=\"'" + " + document.getElementsByTagName(\"base\")[0].href" + " + 'favicon.$1.ico\">')</script>"); if (GOOGLE_ANALYTICS_TRACKING_ID != null) { // this is for demo.glowroot.org indexHtml = indexHtml.replace("</body>", "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]" + "||function(){(i[r].q=i[r].q||[]).push(arguments)}," + "i[r].l=1*new Date();a=s.createElement(o)," + "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;" + "m.parentNode.insertBefore(a,m)})(window,document,'script'," + "'//www.google-analytics.com/analytics.js','ga');ga('create', '" + GOOGLE_ANALYTICS_TRACKING_ID + "', 'auto')</script>\n</body>"); }/*from w w w. jav a 2 s .co m*/ CommonResponse response = new CommonResponse(OK, MediaType.HTML_UTF_8, indexHtml); // this is needed to override IE 11 "Display intranet sites in Compatibility View" response.setHeader("X-UA-Compatible", "IE=edge"); return response; }
From source file:se.kth.karamel.common.util.IoUtils.java
public static String readContentFromClasspath(String path) throws IOException { URL url = Resources.getResource(path); if (url == null) { throw new IOException("No config.props file found in cookbook"); }/*from w w w .j a v a 2 s .c o m*/ return Resources.toString(url, Charsets.UTF_8); }
From source file:com.eucalyptus.auth.util.ClassPathSystemAccountProvider.java
private static String loadResource(final Class<?> resourceClass, final String resourceName) { try {//w w w. ja v a2 s .c om return Resources.toString(Resources.getResource(resourceClass, resourceName), Charsets.UTF_8); } catch (final IOException e) { throw Throwables.propagate(e); } }
From source file:com.pesegato.MonkeySheet.MSGlobals.java
protected void logBuildInfo() { try {/* ww w.jav a2s . c o m*/ java.net.URL u = Resources.getResource("monkeysheet.build.date"); String build = Resources.toString(u, Charsets.UTF_8); log.info("MonkeySheett build date:" + build); } catch (java.io.IOException e) { log.error("Error reading build info", e); } }
From source file:de.adrodoc55.commons.FileUtils.java
public static String getUtf8String(URL url) { try {/*from w ww. ja va 2 s . co m*/ return Resources.toString(url, UTF_8); } catch (IOException ex) { throw new UndeclaredThrowableException(ex); } }