List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
From source file:li.klass.fhem.service.DeviceConfigurationProvider.java
@Inject public DeviceConfigurationProvider() { try {/*from ww w . j ava 2 s .c o m*/ options = new JSONObject(Resources.toString( Resources.getResource(DeviceConfigurationProvider.class, "deviceConfiguration.json"), Charsets.UTF_8)); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.sonar.debugging.java.JavaDebuggingRulesDefinition.java
@Nullable private static String readRuleDefinitionResource(String fileName) { URL resource = JavaDebuggingRulesDefinition.class .getResource("/org/sonar/l10n/java/rules/debugging/" + fileName); if (resource == null) { return null; }/*from w w w. jav a 2 s.c om*/ try { return Resources.toString(resource, Charsets.UTF_8); } catch (IOException e) { throw new IllegalStateException("Failed to read: " + resource, e); } }
From source file:com.streamsets.datacollector.vault.api.VaultTestBase.java
protected String getBody(String path) throws IOException { return Resources.toString(Resources.getResource(path), Charsets.UTF_8); }
From source file:li.klass.fhem.service.deviceConfiguration.DeviceDescMapping.java
@Inject public DeviceDescMapping() { try {/*from w ww. j a va 2 s . c om*/ mapping = new JSONObject(Resources.toString( Resources.getResource(DeviceConfigurationProvider.class, "deviceDescMapping.json"), Charsets.UTF_8)); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.mayocat.shop.shipping.rest.resource.DestinationsResource.java
@GET @Path("flat") public Response getDestinationsFlat() { try {/*from w w w. j a v a2s. com*/ return Response.ok(Resources.toString( Resources.getResource("org/mayocat/shop/shipping/destinations/earth_flat.json"), Charsets.UTF_8)).build(); } catch (IOException e) { this.logger.error("Failed to get location file", e); return Response.serverError().build(); } }
From source file:com.facebook.presto.server.ThreadResource.java
@GET @Path("/ui/thread") @Produces(MediaType.TEXT_HTML)/*from w ww . j a v a 2s. c om*/ public String getUi() throws IOException { return Resources.toString(getResource(getClass(), "thread.html"), StandardCharsets.UTF_8); }
From source file:org.apache.wicket.examples.base.MarkdownArticleModel.java
@Override protected String load() { String text;/*from w w w .ja v a 2 s .c o m*/ try { text = Resources.toString(Resources.getResource(parent, path), Charset.forName("utf-8")); } catch (IOException e) { throw new WicketRuntimeException("Unable to load " + path + " relative to " + parent.getName(), e); } return text; }
From source file:com.cloudera.oryx.app.serving.AbstractConsoleResource.java
@PostConstruct public final void loadHTML() throws IOException { StringBuilder htmlBuilder = new StringBuilder(10000); for (String resource : new String[] { "console-header.html.fragment", getConsoleResource(), "console-footer.html.fragment" }) { URL resourceURL = Resources.getResource(AbstractConsoleResource.class, resource); htmlBuilder.append(Resources.toString(resourceURL, StandardCharsets.UTF_8)); }/* www .j av a 2s . co m*/ html = htmlBuilder.toString(); }
From source file:org.apache.isis.schema.utils.CommandDtoUtils.java
public static CommandDto fromXml(final Class<?> contextClass, final String resourceName, final Charset charset) throws IOException { final URL url = Resources.getResource(contextClass, resourceName); final String s = Resources.toString(url, charset); return fromXml(new StringReader(s)); }
From source file:uk.os.vt.mbtiles.Util.java
/** * Legacy from file./*w w w. j a v a 2 s . c om*/ * * <p>Note: please see RxJDBC DatabaseCreator:62 with: * public static void createDatabase(Connection c) { * * @param file the file * @throws IOException thrown on IO error */ private static void legacyMaker(File file) throws IOException { Connection connection = null; try { connection = getConnection(file); final URL url = Resources.getResource("mbtiles_schema.sql"); final String sql = Resources.toString(url, Charsets.UTF_8); final Statement statement = connection.createStatement(); statement.setQueryTimeout(STATEMENT_QUERY_TIMEOUT_IN_SECONDS); statement.executeUpdate(sql); // replaced statement.execute(text); because multi statement SQL statement.close(); } catch (IOException | SQLException ex) { throw new IOException("cannot produce a valid MBTiles file", ex); } finally { try { if (connection != null) { connection.close(); } } catch (final SQLException ex) { // connection close failed. LOG.error("cannot close connection", ex); } } }