List of usage examples for com.google.common.io Resources asByteSource
public static ByteSource asByteSource(URL url)
From source file:de.unima.core.io.file.xes.OntModelToXLogExporter.java
private static OntModel loadSchemaFromFile() { OntModel schemaModel = ModelFactory.createOntologyModel(new OntModelSpec(OntModelSpec.OWL_MEM)); try (InputStream schemaInputStream = Resources.asByteSource(Resources.getResource(SCHEMAPATH)) .openBufferedStream()) {/* w ww. j a v a 2s . co m*/ schemaModel.read(schemaInputStream, null); } catch (IOException e) { throw Throwables.propagate(e); } return schemaModel; }
From source file:com.github.jsdossier.DefaultDocTemplate.java
private static TemplateFile loadResourceFile(String name, String path) { URL url = DefaultDocTemplate.class.getResource(path); checkNotNull(url, "Resource not found: %s", path); return new TemplateFile(Resources.asByteSource(url), name); }
From source file:de.unima.core.io.file.XESImporter.java
private static InputStream openStream(final String resourceName) { final URL fileUrl = Resources.getResource(resourceName); try {/*w w w . j a va 2 s.c o m*/ return Resources.asByteSource(fileUrl).openStream(); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:br.com.objectos.jabuticava.debs.CaracteristicasFalso.java
private static File gunzip(Class<?> contextClass, String resourceName) { try {/*from w ww. ja v a2s .c o m*/ File file = File.createTempFile("way-io-", ".fak"); URL url = getUrl(contextClass, resourceName); InputStream input = Resources.asByteSource(url).openStream(); GZIPInputStream gzip = new GZIPInputStream(input); org.testng.reporters.Files.copyFile(gzip, file); return file; } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:com.basistech.rosette.dm.test.OsgiTestUtil.java
/** * Assume that a test has a dependencies.properties in the classpath, and use it to retrieve the version. * @param groupId maven group id/*from w ww . j av a 2 s . c o m*/ * @param artifactId maven artifact id * @return the version string */ public static String getDependencyVersion(String groupId, String artifactId) { URL depPropsUrl = Resources.getResource("META-INF/maven/dependencies.properties"); Properties depProps = new Properties(); try { depProps.load(Resources.asByteSource(depPropsUrl).openStream()); } catch (IOException e) { throw new RuntimeException(e); } String ver = (String) depProps.get(String.format("%s/%s/version", groupId, artifactId)); if (ver == null) { throw new RosetteRuntimeException(String.format("No version available for %s:%s", groupId, artifactId)); } ver = ver.replace("-SNAPSHOT", ".SNAPSHOT"); return ver; }
From source file:org.n52.youngs.control.Main.java
public static Report dabGmd() throws Exception { Source source = new KvpCswSource("http://api.eurogeoss-broker.eu/dab/services/cswiso", Collections.singleton("http://www.isotc211.org/2005/gmd"), NamespaceContextImpl.create(), "gmd:MD_Metadata", "http://www.isotc211.org/2005/gmd"); MappingConfiguration configuration = new YamlMappingConfiguration( Resources.asByteSource(Resources.getResource("mappings/gmd-metadata.yml")).openStream(), new XPathHelper()); Mapper mapper = new CswToBuilderMapper(configuration); String host = "localhost"; String cluster = "ConnectinGEO"; String index = "geodab"; String type = "isorecord"; int port = 9301; Sink sink = new ElasticsearchRemoteHttpSink(host, port, cluster, index, type); Runner runner = new SingleThreadBulkRunner().setBulkSize(10).setRecordsLimit(10000).setStartPosition(10000) .harvest(source).transform(mapper); Report report = runner.load(sink);/*from w ww. j av a2 s. co m*/ return report; }
From source file:ratpack.config.internal.source.JacksonConfigSource.java
public JacksonConfigSource(URL url) { this(Resources.asByteSource(url)); }
From source file:org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper.java
public static SchemaContext entityOwners() { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); final SchemaContext schemaContext; File file = null;/* w ww. j av a2 s.c o m*/ try { file = new File("src/main/yang/entity-owners.yang"); final List<ByteSource> sources = Arrays.asList(Resources.asByteSource(file.toURI().toURL())); try { schemaContext = reactor.buildEffective(sources); } catch (IOException e1) { throw new ExceptionInInitializerError(e1); } catch (ReactorException e2) { throw new RuntimeException("Unable to build schema context from " + sources, e2); } return schemaContext; } catch (MalformedURLException e3) { throw new RuntimeException("Malformed URL detected in " + file, e3); } }
From source file:org.glowroot.container.impl.DelegatingJavaagent.java
static File createDelegatingJavaagentJarFile(File dir) throws Exception { File jarFile = File.createTempFile("glowroot-", ".jar", dir); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Premain-Class"), DelegatingJavaagent.class.getName()); manifest.getMainAttributes().put(new Attributes.Name("Can-Redefine-Classes"), "true"); manifest.getMainAttributes().put(new Attributes.Name("Can-Retransform-Classes"), "true"); JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile), manifest); String resourceName = ClassNames.toInternalName(DelegatingJavaagent.class.getName()) + ".class"; out.putNextEntry(new JarEntry(resourceName)); Resources.asByteSource(Resources.getResource(resourceName)).copyTo(out); out.closeEntry();/*from w w w .j ava 2 s. c om*/ out.close(); return jarFile; }
From source file:org.glowroot.agent.it.harness.impl.DelegatingJavaagent.java
static File createDelegatingJavaagentJarFile(File dir) throws Exception { File jarFile = File.createTempFile("glowroot-", ".jar", dir); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Premain-Class"), DelegatingJavaagent.class.getName()); manifest.getMainAttributes().put(new Attributes.Name("Can-Redefine-Classes"), "true"); manifest.getMainAttributes().put(new Attributes.Name("Can-Retransform-Classes"), "true"); String resourceName = ClassNames.toInternalName(DelegatingJavaagent.class.getName()) + ".class"; JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile), manifest); try {//from ww w .j a va 2s.c o m out.putNextEntry(new JarEntry(resourceName)); Resources.asByteSource(Resources.getResource(resourceName)).copyTo(out); out.closeEntry(); } finally { out.close(); } return jarFile; }