List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
From source file:name.marcelomorales.siqisiqi.examples.simple.init.InitialData.java
@Override @TransactionAttribute//w w w . j a v a 2 s.co m public void populate() { try { URL resource = Resources.getResource("dml.sql"); String s = Resources.toString(resource, Charsets.US_ASCII); Iterable<String> split = Splitter.on(';').omitEmptyStrings().trimResults().split(s); for (String sql : split) { jdbcTemplate.execute(sql); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.lanternpowered.server.plugin.InfoPluginContainer.java
/** * Reads a {code plugin.info} file as {@link PluginMetadata} from the * specified plugin id and resource {@link URL}. * * @param pluginId The plugin id/*from w ww . j a v a 2s .com*/ * @param url The resource url * @return The parsed plugin metadata */ public static PluginMetadata readPluginInfo(String pluginId, URL url) throws IOException { final String json = Resources.toString(url, StandardCharsets.UTF_8); JsonElement element = gson.fromJson(json, JsonElement.class); final JsonObject object; if (element.isJsonArray()) { // Just get the first element from the array object = element.getAsJsonArray().get(0).getAsJsonObject(); } else { // The info is directly serialized as an object, get this object // and put it into an array, this is what the McModInfo library // supports object = element.getAsJsonObject(); final JsonArray array = new JsonArray(); array.add(object); element = array; } // Add the 'modid', it is required for the McModInfo object.addProperty("modid", pluginId); // Convert the element back to json and parse it with the McModInfo library final StringReader reader = new StringReader(gson.toJson(element)); return McModInfo.builder().build().read(reader).get(0); }
From source file:com.qualinsight.plugins.sonarqube.smell.plugin.extension.SmellRulesDefinition.java
@Nullable private static String readRuleDefinitionResource(final String fileName) { final URL resource = SmellRulesDefinition.class.getResource("/org/sonar/l10n/java/rules/smell/" + fileName); if (resource == null) { return null; }// w w w . j a va 2 s.com try { return Resources.toString(resource, StandardCharsets.UTF_8); } catch (final IOException e) { throw new IllegalStateException("Failed to read: " + resource, e); } }
From source file:hu.holdinarms.resource.HtmlPageResource.java
/** * Get the index.html./* w w w .j av a 2 s.co m*/ * * @return The page content. */ @GET public Response index() { String pageContent = ""; try { URL clientPage = Resources.getResource("index.html"); pageContent = Resources.toString(clientPage, Charsets.UTF_8); } catch (IOException e) { return Response.serverError().build(); } return Response.ok(pageContent).build(); }
From source file:com.github.marabou.view.LicenceWindow.java
public void showLicence() { shell.setText(_("Licence")); shell.setImage(new ImageLoader().getImage(AvailableImage.LOGO_SMALL)); RowLayout rowLayout = new RowLayout(1); rowLayout.center = true;// w w w. j av a 2 s. c o m rowLayout.marginBottom = 10; rowLayout.marginTop = 10; rowLayout.marginLeft = 10; rowLayout.marginRight = 10; shell.setLayout(rowLayout); // close window on ESC shell.addListener(SWT.Traverse, new Listener() { @Override public void handleEvent(Event event) { if (event.detail == SWT.TRAVERSE_ESCAPE) { shell.dispose(); } } }); // label Label label = new Label(shell, SWT.NONE); label.setAlignment(SWT.CENTER); URL url = Resources.getResource("licence.txt"); String licenceText; try { licenceText = Resources.toString(url, Charsets.UTF_8); } catch (IOException e) { licenceText = "error reading licence file"; } label.setText(licenceText); label.pack(); // close button Button close = new Button(shell, SWT.NONE); close.setText(_("&Close")); close.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { shell.dispose(); } }); close.setFocus(); close.pack(); shell.pack(); shell.open(); // close also if display gets disposed while (!shell.isDisposed() && display.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
From source file:net.minecraftforge.gradle.util.mcp.GLConstantFixer.java
public GLConstantFixer() throws IOException { String text = Resources.toString(Resources.getResource(GLConstantFixer.class, "gl.json"), Charset.defaultCharset()); json = JsonFactory.GSON.fromJson(text, new TypeToken<List<GLConstantGroup>>() { }.getType());/* w w w.j av a 2s . c o m*/ }
From source file:org.icgc.dcc.portal.manifest.writer.EGAManifestWriter.java
private static String readTemplate() throws IOException { return Resources.toString(EGAManifestWriter.class.getResource(MANIFEST_TEMPLATE), UTF_8); }
From source file:com.facebook.presto.example.LuceneClient.java
private static Map<String, Map<String, LuceneTable>> lookupSchemas(URI metadataUri, JsonCodec<Map<String, List<LuceneTable>>> catalogCodec) throws IOException { URL result = metadataUri.toURL(); String json = Resources.toString(result, UTF_8); Map<String, List<LuceneTable>> catalog = catalogCodec.fromJson(json); return ImmutableMap.copyOf(transformValues(catalog, resolveAndIndexTables(metadataUri))); }
From source file:org.glowroot.local.ui.IndexHtmlHttpService.java
@Override public FullHttpResponse handleRequest(ChannelHandlerContext ctx, HttpRequest request) throws Exception { URL url = Resources.getResource("org/glowroot/local/ui/app-dist/index.html"); String indexHtml = Resources.toString(url, Charsets.UTF_8); String layout;//from ww w. j av a 2 s. com if (httpSessionManager.hasReadAccess(request)) { layout = layoutJsonService.getLayout(); } else { layout = layoutJsonService.getNeedsAuthenticationLayout(); } String authenticatedUser = httpSessionManager.getAuthenticatedUser(request); String layoutScript = "var layout=" + layout + ";var authenticatedUser = " + authenticatedUser; indexHtml = indexHtml.replaceFirst("<base href=\"/\">", "<base href=\"" + BASE_HREF + "\"><script>" + layoutScript + "</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.replaceFirst("<div class=\"navbar-brand\">(\\s*)Glowroot(\\s*)</div>", "<a href=\"https://glowroot.org\" class=\"navbar-brand\">$1Glowroot$2</a>"); indexHtml = indexHtml.replaceFirst("</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>"); } ByteBuf content = Unpooled.copiedBuffer(indexHtml, Charsets.ISO_8859_1); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content); HttpServices.preventCaching(response); response.headers().set(Names.CONTENT_TYPE, "text/html; charset=UTF-8"); response.headers().set(Names.CONTENT_LENGTH, indexHtml.length()); // X-UA-Compatible must be set via header (as opposed to via meta tag) // see https://github.com/h5bp/html5-boilerplate/blob/master/doc/html.md#x-ua-compatible response.headers().set("X-UA-Compatible", "IE=edge"); return response; }
From source file:com.facebook.presto.example.ExampleClient.java
private static Map<String, Map<String, ExampleTable>> lookupSchemas(URI metadataUri, JsonCodec<Map<String, List<ExampleTable>>> catalogCodec) throws IOException { URL result = metadataUri.toURL(); String json = Resources.toString(result, UTF_8); Map<String, List<ExampleTable>> catalog = catalogCodec.fromJson(json); return ImmutableMap.copyOf(transformValues(catalog, resolveAndIndexTables(metadataUri))); }