List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:com.streamsets.datacollector.kafka.standalone.KafkaDestinationSinglePartitionPipelineRunIT.java
@Override protected String getPipelineJson() throws Exception { URI uri = Resources.getResource("kafka_destination_pipeline_run.json").toURI(); String pipelineJson = new String(Files.readAllBytes(Paths.get(uri)), StandardCharsets.UTF_8); pipelineJson = pipelineJson.replace("topicName", TOPIC); pipelineJson = pipelineJson.replaceAll("localhost:9092", KafkaTestUtil.getMetadataBrokerURI()); pipelineJson = pipelineJson.replaceAll("localhost:2181", KafkaTestUtil.getZkServer().connectString()); return pipelineJson; }
From source file:com.aerofs.baseline.config.Configuration.java
@SuppressWarnings("unchecked") public static <C extends Configuration> C loadYAMLConfigurationFromResources(Class<?> derived, String configFile) throws IOException { try (FileInputStream in = new FileInputStream(Resources.getResource(configFile).getFile())) { return Configuration.loadYAMLConfigurationFromStream(derived, in); }/* ww w.j a va2 s . c o m*/ }
From source file:name.marcelomorales.siqisiqi.examples.simple.init.InitialData.java
@Override @TransactionAttribute//from w ww . j ava2s . c o m public void populate() { try { URL resource = Resources.getResource("dml.sql"); String s = Resources.toString(resource, Charsets.US_ASCII); Iterable<String> split = Splitter.on(';').omitEmptyStrings().trimResults().split(s); for (String sql : split) { jdbcTemplate.execute(sql); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.flume.channel.file.encryption.EncryptionTestUtils.java
public static Map<String, File> configureTestKeyStore(File baseDir, File keyStoreFile) throws IOException { Map<String, File> result = Maps.newHashMap(); if (System.getProperty("java.vendor").contains("IBM")) { Resources.copy(Resources.getResource("ibm-test.keystore"), new FileOutputStream(keyStoreFile)); } else {//from w ww .j a v a2 s . co m Resources.copy(Resources.getResource("sun-test.keystore"), new FileOutputStream(keyStoreFile)); } /* Commands below: keytool -genseckey -alias key-0 -keypass keyPassword -keyalg AES \ -keysize 128 -validity 9000 -keystore src/test/resources/test.keystore \ -storetype jceks -storepass keyStorePassword keytool -genseckey -alias key-1 -keyalg AES -keysize 128 -validity 9000 \ -keystore src/test/resources/test.keystore -storetype jceks \ -storepass keyStorePassword */ // key-0 has own password, key-1 used key store password result.put("key-0", TestUtils.writeStringToFile(baseDir, "key-0", "keyPassword")); result.put("key-1", null); return result; }
From source file:org.atlasapi.output.rdf.JenaRdfTranslator.java
public void initOntologies() { for (Map.Entry<String, String> ontology : ontologyMap.entrySet()) { URL ontologyUrl;/* ww w .ja v a 2 s .c o m*/ try { ontologyUrl = Resources.getResource(ontology.getValue()); } catch (Exception e) { throw new IllegalStateException("Failed to load ontology file " + ontology.getValue(), e); } documentMgr.addAltEntry(ontology.getKey(), ontologyUrl.toString()); } }
From source file:net.nokok.twitduke.resources.FXMLResources.java
private static Optional<URL> findFXMLResources(String resource) { return Optional.ofNullable(Resources.getResource(String.join(File.separator, "fxml", resource))); }
From source file:com.mapr.synth.distributions.WordGenerator.java
public WordGenerator(String seed, String others) { // read the common words if (seed != null) { try {//from ww w . j av a 2 s . c o m Resources.readLines(Resources.getResource(seed), Charsets.UTF_8, new LineProcessor<Object>() { private boolean header = true; private final Splitter onTabs = Splitter.on("\t"); public boolean processLine(String s) throws IOException { if (!s.startsWith("#")) { if (!header) { Iterator<String> fields = onTabs.split(s).iterator(); fields.next(); String word = fields.next(); words.add(word); int count = (int) Math.rint(Double.parseDouble(fields.next())); baseWeights.put(word, count); } else { header = false; } } return true; } public Object getResult() { return null; } }); } catch (IOException e) { log.error("Can't read resource \"{}\", will continue without realistic words", seed); } } try { wordReader = new BufferedReader( Resources.newReaderSupplier(Resources.getResource(others), Charsets.UTF_8).getInput()); } catch (IOException e) { log.error("Can't read resource \"{}\", will continue without realistic words", others); wordReader = null; } }
From source file:org.killbill.billing.server.updatechecker.ProductInfo.java
private void parseProductInfo(final String resource) throws IOException { final URL resourceURL = Resources.getResource(resource); final InputStream inStream = resourceURL.openStream(); try {// w ww . ja v a 2 s . c om props.load(inStream); } finally { inStream.close(); } }
From source file:com.github.marabou.view.LicenceWindow.java
public void showLicence() { shell.setText(_("Licence")); shell.setImage(new ImageLoader().getImage(AvailableImage.LOGO_SMALL)); RowLayout rowLayout = new RowLayout(1); rowLayout.center = true;//from www . j a va2 s .c o m rowLayout.marginBottom = 10; rowLayout.marginTop = 10; rowLayout.marginLeft = 10; rowLayout.marginRight = 10; shell.setLayout(rowLayout); // close window on ESC shell.addListener(SWT.Traverse, new Listener() { @Override public void handleEvent(Event event) { if (event.detail == SWT.TRAVERSE_ESCAPE) { shell.dispose(); } } }); // label Label label = new Label(shell, SWT.NONE); label.setAlignment(SWT.CENTER); URL url = Resources.getResource("licence.txt"); String licenceText; try { licenceText = Resources.toString(url, Charsets.UTF_8); } catch (IOException e) { licenceText = "error reading licence file"; } label.setText(licenceText); label.pack(); // close button Button close = new Button(shell, SWT.NONE); close.setText(_("&Close")); close.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { shell.dispose(); } }); close.setFocus(); close.pack(); shell.pack(); shell.open(); // close also if display gets disposed while (!shell.isDisposed() && display.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
From source file:com.huangyunkun.jviff.core.impl.HtmlResultReport.java
@Override public void report(List<StepResult> stepResults, File outputDir) throws IOException { Iterable<StepResult> stepResultIterable = Iterables.filter(stepResults, new Predicate<StepResult>() { @Override/*w w w . j a v a 2s . c om*/ public boolean apply(StepResult input) { return input.getStep().getRecord(); } }); final Context ctx = new Context(); ctx.setVariable("stepResults", stepResultIterable); String templateFile = Resources.getResource("html/index.html").getPath(); String html = templateEngine.process(templateFile, ctx); File outputFile = new File(outputDir, "index.html"); Files.write(html, outputFile, Charset.forName("utf8")); copyResources(outputDir); }