List of usage examples for com.google.common.io Resources asByteSource
public static ByteSource asByteSource(URL url)
From source file:de.ii.ldproxy.rest.SwaggerApiResource.java
@GET public Response getApi() { StreamingOutput stream = new StreamingOutput() { @Override/*from w w w .j a v a2 s .c om*/ public void write(OutputStream output) throws IOException, WebApplicationException { Resources.asByteSource(Resources.getResource(SwaggerApiResource.class, "/swagger/swagger.json")) .copyTo(output); } }; return Response.ok(stream).build(); }
From source file:com.zxy.commons.lang.conf.AbstractConfigProperties.java
/** * ?Properties//ww w. j a v a 2 s .c o m * * @return Properties * @throws IOException */ @SuppressWarnings("PMD.EmptyCatchBlock") private Properties load() throws IOException { // final URL url = Resources.getResource(resource); final URL url = getPath(); final ByteSource byteSource = Resources.asByteSource(url); final Properties properties = new Properties(); InputStream inputStream = null; try { inputStream = byteSource.openBufferedStream(); properties.load(inputStream); // properties.list(System.out); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException ioException) { // do nothing } } } return properties; }
From source file:ratpack.configuration.internal.DefaultConfigurationSource.java
public DefaultConfigurationSource(ClassLoader classLoader, URL url, Properties overrideProperties, Properties defaultProperties) { this(classLoader, Resources.asByteSource(url), overrideProperties, defaultProperties); }
From source file:org.infinitest.eclipse.InfinitestCoreClasspath.java
private static void writeJar(File coreJarLocation, InfinitestPlugin plugin) { // Only for tests -> if (plugin != null) // <-// w w w .j a v a 2s . com { Enumeration<?> e = plugin.getPluginBundle().findEntries("", "*infinitest-runner*.jar", true); if (e == null) { log(SEVERE, "Error creating testrunner classpath. Cannot find infinitest core bundle"); } else { while (e.hasMoreElements()) { URL url = (URL) e.nextElement(); try { Resources.asByteSource(url).copyTo(Files.asByteSink(coreJarLocation)); } catch (IOException e1) { log(SEVERE, "Error creating testrunner classpath. Could not write to " + coreJarLocation); throw new RuntimeException(e1); } } } } }
From source file:org.n52.javaps.Base.java
public String pox(String filename) throws IOException { URL url = Resources.getResource("requests/" + filename); InputStream request = Resources.asByteSource(url).openBufferedStream(); return Request.Post(getEndpointURL()).bodyStream(request, ContentType.APPLICATION_XML).execute() .returnContent().asString(); }
From source file:com.epam.reportportal.utils.properties.PropertiesLoader.java
/** * Try to load properties from file situated in the class path, and then * reload existing parameters from environment variables * * @return/*from w ww .j a va 2 s.c o m*/ * @throws IOException */ private static Properties loadProperties() throws IOException { Properties props = new Properties(); Optional<URL> propertyFile = getResource(INNER_PATH); if (propertyFile.isPresent()) { props.load(Resources.asByteSource(propertyFile.get()).openBufferedStream()); } reloadFromSystemProperties(props); reloadFromEnvVariables(props); reloadFromSoapUI(props); validateProperties(props); reloadProperties(props); setProxyProperties(props); return props; }
From source file:org.n52.youngs.control.Main.java
public static Report dabCsw() throws Exception { // http://api.eurogeoss-broker.eu/dab/services/cswiso?service=CSW&version=2.0.2&request=GetCapabilities Source source = new KvpCswSource("http://api.eurogeoss-broker.eu/dab/services/cswiso", Collections.singleton("http://www.opengis.net/cat/csw/2.0.2"), NamespaceContextImpl.create(), "csw:Record", "http://www.opengis.net/cat/csw/2.0.2"); MappingConfiguration configuration = new YamlMappingConfiguration( Resources.asByteSource(Resources.getResource("mappings/csw-record.yml")).openStream(), new XPathHelper()); Mapper mapper = new CswToBuilderMapper(configuration); String host = "localhost"; String cluster = "ConnectinGEO"; String index = "geodab"; String type = "dcrecord"; int port = 9301; Sink sink = new ElasticsearchRemoteHttpSink(host, port, cluster, index, type); Runner runner = new SingleThreadBulkRunner().setBulkSize(20).setRecordsLimit(10).setStartPosition(1) .harvest(source).transform(mapper); Report report = runner.load(sink);//from w ww . ja v a 2 s .c o m return report; }
From source file:com.feedeo.shopify.web.client.rest.ShopifyOAuth2RestClient.java
private static Properties getProperties() { final Properties properties = new Properties(); final URL url = Resources.getResource("jopify.properties"); final ByteSource byteSource = Resources.asByteSource(url); InputStream inputStream = null; try {/*from www. j a va 2 s . c o m*/ inputStream = byteSource.openBufferedStream(); properties.load(inputStream); } catch (final IOException ioException) { ioException.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (final IOException ioException) { ioException.printStackTrace(); } } } return properties; }
From source file:com.arcbees.website.server.HomeServlet.java
private Properties loadVelocityProperties() { Properties properties = new Properties(); try {/* www . ja va 2s. co m*/ URL url = Resources.getResource(VELOCITY_PROPERTIES); ByteSource byteSource = Resources.asByteSource(url); properties.load(byteSource.openStream()); } catch (Exception e) { throw new RuntimeException("Unable to load velocity properties from '" + VELOCITY_PROPERTIES + "'.", e); } return properties; }
From source file:at.ac.univie.isc.asio.io.Classpath.java
/** * Load a resource from the classpath and wrap it as a {@code ByteSource}. * * @param name name of the resource/*from www.j a va 2s . c o m*/ * @return the wrapped resource * @throws java.lang.IllegalArgumentException if the resource is not found */ @Nonnull public static ByteSource load(@Nonnull final String name) throws IllegalArgumentException { Preconditions.checkArgument(!name.startsWith("/"), "illegal resource name <%s> - resource names may not have a leading slash, they are implicitly absolute", name); final URL url = Resources.getResource(name); return Resources.asByteSource(url); }