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.indeed.imhotep.web.BashScriptServlet.java
@RequestMapping("/iql.sh") @ResponseBody/*ww w . ja v a 2 s .co m*/ protected String doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setHeader("content-disposition", "attachment; filename=iql.sh"); final String server = req.getServerName(); final String protocol; if (server.contains("qa.indeed") || server.contains("stage.indeed") || server.contains("indeed.com")) { protocol = "https://"; } else { protocol = "http://"; } final URL scriptResourceURL = Resources.getResource("iql.sh"); final String script = Resources.toString(scriptResourceURL, Charsets.UTF_8); final String serverURLVariable = "SERVER_URL=" + protocol + server + ":" + req.getServerPort() + req.getContextPath() + "/query\n"; return serverURLVariable + script; }
From source file:org.apache.isis.core.runtime.services.menubars.MenuBarsLoaderServiceDefault.java
@Override public BS3MenuBars menuBars() { final AppManifest appManifest = isisSessionFactory.getAppManifest(); try {/*from w w w . ja v a 2s . c o m*/ final URL resource = Resources.getResource(appManifest.getClass(), "menubars.layout.xml"); String xml = Resources.toString(resource, Charsets.UTF_8); return jaxbService.fromXml(BS3MenuBars.class, xml); } catch (Exception e) { return null; } }
From source file:org.apache.isis.core.runtime.services.menu.MenuBarsLoaderServiceDefault.java
@Override public MenuBars menuBars() { final AppManifest appManifest = isisSessionFactory.getAppManifest(); final URL resource = Resources.getResource(appManifest.getClass(), "menubars.layout.xml"); try {/*from ww w. jav a2 s . co m*/ String xml = Resources.toString(resource, Charsets.UTF_8); return jaxbService.fromXml(MenuBars.class, xml); } catch (IOException e) { return null; } }
From source file:com.facebook.buck.lua.LuaInPlaceBinary.java
private static String getRunInplaceResource() { try {/*from w w w . ja va2 s . c o m*/ return Resources.toString(Resources.getResource(RUN_INPLACE_RESOURCE), Charsets.UTF_8); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:com.eucalyptus.auth.util.ClassPathSystemRoleProvider.java
private String loadPolicy(final String resourceName) { try {// ww w. j av a 2 s . c om return Resources.toString(Resources.getResource(getClass(), resourceName), Charsets.UTF_8); } catch (final IOException e) { throw Exceptions.toUndeclared(e); } }
From source file:com.nesscomputing.migratory.loader.ClasspathLoader.java
/** * This method loads a file from a classpath:/... URI. *//* www .ja v a 2 s .co m*/ @Override public String loadFile(final URI fileUri) { try { final URL urlLocation = Resources.getResource(this.getClass(), fileUri.getPath()); return Resources.toString(urlLocation, Charsets.UTF_8); } catch (IOException e) { throw new MigratoryException(Reason.INTERNAL, e); } }
From source file:com.facebook.buck.features.project.intellij.StringTemplateFile.java
/** * Not thread safe, see discussion in: https://github.com/antlr/stringtemplate4/issues/61 could be * made faster by sharing STGroup across threads using a supplier, see {@link * com.facebook.buck.parser.function.BuckPyFunction}. May be fixed in ST4.1 */// w w w. j a v a2s. c om public synchronized ST getST() throws IOException { URL templateUrl = Resources.getResource(StringTemplateFile.class, "templates/" + fileName); String template = Resources.toString(templateUrl, StandardCharsets.UTF_8); return new ST(template, DELIMITER, DELIMITER); }
From source file:io.hops.hopsworks.common.util.IoUtils.java
public static String readContentFromClasspath(String path) throws IOException { URL url = IoUtils.class.getResource(path);// Resources.getResource(path); if (url == null) { throw new IOException("No config.props file found in cookbook"); }//from w w w .j av a2 s . c o m return Resources.toString(url, Charsets.UTF_8); }
From source file:org.jmxtrans.embedded.samples.graphite.GraphiteDataInjector.java
public static GraphiteDataInjector newHostedGraphiteDataInjector() { GraphiteDataInjector graphiteDataInjector = new GraphiteDataInjector(); // TODO DEFINE YOUR_HOSTED_GRAPHITE_KEY String hostedGraphiteKey = null; try {//from w ww .j av a 2s .c o m hostedGraphiteKey = Resources.toString(Resources.getResource("hosted-graphite.credentials"), Charset.defaultCharset()); } catch (IOException e) { throw Throwables.propagate(e); } graphiteDataInjector.graphiteMetricPrefix = hostedGraphiteKey + ".edu.servers."; graphiteDataInjector.graphiteHost = "carbon.hostedgraphite.com"; graphiteDataInjector.setMaxGraphiteDataPointsPerSecond(100); graphiteDataInjector.batchSize = 50; return graphiteDataInjector; }
From source file:li.klass.fhem.fragments.FloorplanFragment.java
@Override protected void onPageLoadFinishedCallback(final WebView view, String url) { if (url.contains("&XHR=1")) { view.loadUrl(getLoadUrl());/* ww w . j a v a 2s. com*/ return; } URL modifyJsUrl = FloorplanFragment.class.getResource("floorplan-modify.js"); try { final String modifyJs = Resources.toString(modifyJsUrl, Charset.forName("UTF-8")); BuildVersion.execute(new BuildVersion.VersionDependent() { @Override public void ifBelow() { view.loadUrl("javascript:" + modifyJs); } @Override @SuppressLint("NewApi") public void ifAboveOrEqual() { view.evaluateJavascript(modifyJs, null); } }, 19); view.loadUrl("javascript:" + modifyJs); } catch (Exception e) { Log.e(TAG, "cannot load floorplan-modify.js", e); } }