List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:net.nokok.twitduke.resources.ImageResources.java
private static Image getImage(String fileName) { try {// www .jav a2s. co m String path = Resources.getResource(String.join(File.separator, "img", fileName)).toURI().toString(); return new Image(path); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:com.ning.billing.util.config.catalog.UriAccessor.java
public static InputStream accessUri(URI uri) throws IOException, URISyntaxException { String scheme = uri.getScheme(); URL url = null;//from w ww .jav a2 s. co m if (scheme == null) { uri = new URI(Resources.getResource(uri.toString()).toExternalForm()); } else if (scheme.equals(URI_SCHEME_FOR_CLASSPATH)) { return UriAccessor.class.getResourceAsStream(uri.getPath()); } else if (scheme.equals(URI_SCHEME_FOR_FILE) && !uri.getSchemeSpecificPart().startsWith("/")) { // interpret URIs of this form as relative path uris url = new File(uri.getSchemeSpecificPart()).toURI().toURL(); } url = uri.toURL(); return url.openConnection().getInputStream(); }
From source file:ec.tss.tsproviders.spreadsheet.Top5BrowsersHelper.java
public static URL getURL(String type) { return Resources.getResource("Top5Browsers." + type); }
From source file:com.streamsets.datacollector.multiple.MultiplePipelinesDevIT.java
private static List<String> getPipelineJson() throws URISyntaxException, IOException { //random to kafka URI uri = Resources.getResource("dev_multiple_pipelines.json").toURI(); String devMultiplePipelines = new String(Files.readAllBytes(Paths.get(uri)), StandardCharsets.UTF_8); List<String> multiplePipelines = new ArrayList<>(); for (int i = 1; i <= 4; i++) { multiplePipelines.add(devMultiplePipelines.replaceAll("\"name\" : \"dev_multiple_pipelines\"", "\"name\" : \"dev_multiple_pipelines" + i + "\"")); }/*from ww w .j a v a2 s . c o m*/ return multiplePipelines; }
From source file:org.killbill.billing.util.config.catalog.UriAccessor.java
public static InputStream accessUri(URI uri) throws IOException, URISyntaxException { final String scheme = uri.getScheme(); final URL url; if (scheme == null) { uri = new URI(Resources.getResource(uri.toString()).toExternalForm()); } else if (scheme.equals(URI_SCHEME_FOR_CLASSPATH)) { if (uri.toString().startsWith(URI_SCHEME_FOR_ARCHIVE_FILE)) { return getInputStreamFromJarFile(uri.toString()); } else {//from ww w . j a va2 s . co m return UriAccessor.class.getResourceAsStream(uri.getPath()); } } else if (scheme.equals(URI_SCHEME_FOR_FILE) && !uri.getSchemeSpecificPart().startsWith("/")) { // interpret URIs of this form as relative path uris uri = new File(uri.getSchemeSpecificPart()).toURI(); } url = uri.toURL(); return url.openConnection().getInputStream(); }
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()) {/*from w w w. j av a 2s.co m*/ schemaModel.read(schemaInputStream, null); } catch (IOException e) { throw Throwables.propagate(e); } return schemaModel; }
From source file:com.github.lukaszkusek.assertj.xml.ResourceReader.java
public static URL getURL(final String fileName) { return Resources.getResource("com/github/lukaszkusek/assertj/xml/" + fileName); }
From source file:nlp.TFIDFUtil.java
/** *************************************************************** * @param filename file to be read/*w ww .ja v a2 s. c o m*/ * @param separateSentences should sentences be separated if they occur on one line * @return list of strings from each line of the document * This method reads in a text file, breaking it into single line documents * Currently, sentences are not separated if they occur on the same line. */ public static List<String> readFile(String filename, boolean separateSentences) throws IOException { List<String> documents = Lists.newArrayList(); URL fileURL = Resources.getResource(filename); File f = new File(filename); BufferedReader bf = new BufferedReader(new FileReader(fileURL.getPath())); String line; while ((line = bf.readLine()) != null) { if (line == null || line.equals("")) continue; documents.add(line); } return documents; }
From source file:com.boundary.metrics.vmware.client.MetricClientFactory.java
public static MetricClient createClient(String propertyFile) throws URISyntaxException, IOException { final String URL = "com.boundary.metrics.metric.client.baseuri"; final String AUTH = "com.boundary.metrics.metric.client.auth"; File propertiesFile = new File(Resources.getResource(propertyFile).toURI()); assumeTrue(propertiesFile.exists()); Reader reader = new FileReader(propertiesFile); Properties clientProperties = new Properties(); clientProperties.load(reader);// w w w. ja va2 s .c o m String url = clientProperties.getProperty(URL); String auth = clientProperties.getProperty(AUTH); Client client = new Client(); return new MetricClient(client, new URI(url), auth); }
From source file:org.cloudifysource.cosmo.orchestrator.workflow.RuoteWorkflow.java
public static RuoteWorkflow createFromResource(String resourceName, RuoteRuntime runtime) { Preconditions.checkNotNull(resourceName); Preconditions.checkNotNull(runtime); try {//w w w .j a v a 2s . c o m final URL url = Resources.getResource(resourceName); final String workflow = Resources.toString(url, Charsets.UTF_8); return new RuoteWorkflow(workflow, runtime); } catch (IOException e) { throw Throwables.propagate(e); } }