List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
From source file:org.mayocat.shop.shipping.rest.resource.DestinationsResource.java
@GET public Response getDestinations() { try {/* w w w.j a v a2 s . com*/ return Response.ok(Resources.toString( Resources.getResource("org/mayocat/shop/shipping/destinations/earth.json"), Charsets.UTF_8)) .build(); } catch (IOException e) { this.logger.error("Failed to get location file", e); return Response.serverError().build(); } }
From source file:io.prestosql.geospatial.serde.BenchmarkGeometrySerializationData.java
public static String readResource(String resource) { try {/* w w w. j a v a 2 s . co m*/ return Resources.toString(getResource(resource), UTF_8); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.dgraf.nashornplayground.currencyUtility.java
public currencyUtility() { currencies = new ArrayList<>(); final URL resource = getClass().getResource("currencies.json"); if (resource == null) { throw new IllegalArgumentException("Currencies json file could be loaded from the classpath."); }//from w w w . j av a2 s . c o m try { String cncydata = Resources.toString(resource, Charsets.UTF_8); ObjectMapper mapper = new ObjectMapper(); ArrayList<currency> tmpCurrencies = mapper.readValue(cncydata, new TypeReference<ArrayList<currency>>() { }); currencies.addAll(tmpCurrencies); } catch (IOException ex) { Logger.getLogger(currencyUtility.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.netflix.iep.config.ScopedPropertiesLoader.java
public static Properties load(String[] propFiles) { List<URL> propUrls = new ArrayList<>(); for (int i = 0; i < propFiles.length; i++) { String propFile = propFiles[i]; try {/*from w w w. j a v a 2 s. c o m*/ propUrls.add((Resources.getResource(propFile))); } catch (IllegalArgumentException e) { LOGGER.debug("ignoring " + propFile + " - does not exist"); } } StringBuilder debug = new StringBuilder("# Generated properties\n"); Properties finalProps = new Properties(); for (URL propUrl : propUrls) { LOGGER.debug("loading properties from " + propUrl); String propData; try { propData = Resources.toString(propUrl, Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } String propString = ConfigFile.toPropertiesString(System.getenv(), propData); debug.append(propString).append("\n"); Properties props = ConfigFile.loadProperties(System.getenv(), propData); LOGGER.debug("loading properties: " + props); finalProps.putAll(props); LOGGER.info("loaded properties file " + propUrl); } LOGGER.debug("properties debug: " + debug); return finalProps; }
From source file:com.jdom.junit.utils.FileContentsDownload.java
@Override public String downloadUrlContents(String path) { try {/*from w ww . j a v a2 s .c om*/ return Resources.toString(FileContentsDownload.class.getResource(path), Charset.defaultCharset()); } catch (IOException e) { LOG.error("Error reading path [" + path + "]", e); return null; } }
From source file:org.openhab.binding.netatmo.internal.messages.DeviceListRequestStub.java
private DeviceListRequestStub(final String response) throws Exception { super(ACCESS_TOKEN); final URL resource = getClass().getResource(response); if (resource == null) { throw new IOException("Resource '" + response + "' not found!"); }/* w w w. jav a2 s .com*/ this.response = Resources.toString(resource, Charsets.UTF_8); }
From source file:com.google.api.codegen.ruby.RubyApiaryNameMap.java
@SuppressWarnings("unchecked") private static ImmutableMap<ResourceId, String> getNameMap() throws IOException { String data = Resources.toString(Resources.getResource(RubyApiaryNameMap.class, "apiary_names.yaml"), StandardCharsets.UTF_8); // Unchecked cast here. Map<String, String> nameData = (Map<String, String>) (new Yaml().load(data)); ImmutableMap.Builder<ResourceId, String> builder = ImmutableMap.<ResourceId, String>builder(); for (Map.Entry<String, String> entry : nameData.entrySet()) { builder.put(parseKey(entry.getKey()), entry.getValue()); }/* w ww.j a v a 2s. c o m*/ return builder.build(); }
From source file:org.smartdeveloperhub.curator.connector.util.ResourceUtil.java
private static String load(final String resourceName, final URL resource) throws AssertionError { try {//from w w w . j a v a 2 s.c o m if (resource == null) { throw new AssertionError("Could not find resource '" + resourceName + "'"); } return Resources.toString(resource, Charset.forName("UTF-8")); } catch (final IOException e) { throw new AssertionError("Could not load resource '" + resourceName + "'", e); } }
From source file:com.dgraf.nashornplayground.Bindings.java
public Bindings() { super();/*from w w w . ja v a 2 s . co m*/ runner = new nashornScriptRunner(); scriptset = new nashornScriptset(); try { scriptset.setName("Bindings"); URL url = Resources.getResource("com/dgraf/nashornplayground/examples/bindings.js"); String script = Resources.toString(url, Charsets.UTF_8); scriptset.setScript(script); } catch (IOException ex) { Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.dgraf.nashornplayground.AddingJava.java
public AddingJava() { super();//from w w w .j a va2 s. c om runner = new nashornScriptRunner(); scriptset = new nashornScriptset(); try { scriptset.setName("Adding Java"); URL url = Resources.getResource("com/dgraf/nashornplayground/examples/addingjava.js"); String script = Resources.toString(url, Charsets.UTF_8); scriptset.setScript(script); } catch (IOException ex) { Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex); } }