List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:com.mgmtp.jfunk.data.generator.config.GeneratorModule.java
@Provides @Singleton//from w w w . ja v a2 s. co m @LoremIpsum String provideLoremIpsum() throws IOException { return Resources.toString(Resources.getResource("lorem_ipsum.txt"), Charsets.UTF_8); }
From source file:org.killbill.billing.beatrix.integration.osgi.util.SetupBundleWithAssertion.java
public void setupJrubyBundle() { try {/* ww w. j ava2 s . co m*/ installJrubyJar(); final URL resourceUrl = Resources.getResource(bundleName); final File unzippedRubyPlugin = unGzip(new File(resourceUrl.getFile()), rootInstallDir); final StringBuilder tmp = new StringBuilder(rootInstallDir.getAbsolutePath()); tmp.append("/plugins/").append(PluginLanguage.RUBY.toString().toLowerCase()); final File destination = new File(tmp.toString()); if (!destination.exists()) { Assert.assertTrue(destination.mkdirs(), "Unable to create directory " + destination.getAbsolutePath()); } unTar(unzippedRubyPlugin, destination); } catch (final IOException e) { Assert.fail(e.getMessage()); } catch (final ArchiveException e) { Assert.fail(e.getMessage()); } }
From source file:com.github.fhirschmann.clozegen.lib.adapters.api.URLBasedModelAdapter.java
@SuppressWarnings("unchecked") @Override/* w w w .j a v a 2s . c om*/ public boolean initialize() { @SuppressWarnings("serial") TypeToken<M> type = new TypeToken<M>(getClass()) { }; try { model = (M) type.getRawType().newInstance(); model.load(Resources.getResource(path)); return true; } catch (InstantiationException ex) { getLogger().error(ex); } catch (IllegalAccessException ex) { getLogger().error(ex); } catch (IOException ex) { getLogger().error(ex); } return false; }
From source file:org.apache.omid.YAMLUtils.java
@SuppressWarnings("unchecked") private Map loadAsMap(String path) throws IOException { try {//from w w w. ja va2 s .co m String content = Resources.toString(Resources.getResource(path), Charset.forName("UTF-8")); LOG.debug("Loaded resource file '{}'\n{}", path, content); Map settings = new Yaml().loadAs(content, Map.class); if (settings == null) { settings = new HashMap(0); } return settings; } catch (IllegalArgumentException e) { return new HashMap(); } }
From source file:com.google.javascript.refactoring.RefasterJsScanner.java
/** * Loads the RefasterJs template. This must be called before the scanner is used. *//*from w w w. jav a 2 s. c o m*/ public void loadRefasterJsTemplate(String refasterjsTemplate) throws IOException { Preconditions.checkState(templateJs == null, "Can't load RefasterJs template since a template is already loaded."); this.templateJs = Thread.currentThread().getContextClassLoader().getResource(refasterjsTemplate) != null ? Resources.toString(Resources.getResource(refasterjsTemplate), UTF_8) : Files.toString(new File(refasterjsTemplate), UTF_8); }
From source file:com.eucalyptus.simplequeue.persistence.cassandra.CassandraSessionManager.java
private static void createSchema(final Session session) { // create new keyspace/tables (should not do here) TODO: move session.execute("CREATE KEYSPACE IF NOT EXISTS eucalyptus_simplequeue " + "WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}; "); session.execute("USE eucalyptus_simplequeue;"); try {/*www .ja v a 2 s .com*/ final String cql = Resources.toString( Resources.getResource("2017-03-03-eucalyptus-simplequeue-base.cql"), StandardCharsets.UTF_8); CqlUtil.splitCql(cql).forEach(session::execute); } catch (final IOException | ParseException e) { throw Exceptions.toUndeclared(e); } }
From source file:org.killbill.billing.plugin.meter.MeterTestSuiteWithEmbeddedDB.java
@BeforeSuite(groups = { "slow", "mysql" }) public void startMysqlBeforeTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException { helper.initialize();/*from w ww .java 2s .c om*/ helper.start(); final InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return Resources.getResource("org/killbill/billing/plugin/meter/ddl.sql").openStream(); } }; final String ddl = CharStreams.toString(CharStreams.newReaderSupplier(inputSupplier, Charsets.UTF_8)); helper.executeScript(ddl); helper.refreshTableNames(); }
From source file:org.jsfr.json.BenchmarkParseLargeJsonWithoutStreaming.java
@Setup public void setup() throws IOException { gson = new GsonBuilder().create(); om = new ObjectMapper(); json = Resources.toString(Resources.getResource("allthethings.json"), StandardCharsets.UTF_8); }
From source file:org.apache.s4.core.moduleloader.ModuleLoaderTestUtils.java
public static Process testModuleLoader(boolean fork) throws Exception { Process forkedS4Node = null; // build custom-modules.jar File gradlewFile = CoreTestUtils.findGradlewInRootDir(); CoreTestUtils.callGradleTask(//from www . jav a2 s.c o m new File(gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/custom-modules/build.gradle"), "clean", new String[0]); File modulesJarFile = new File(gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/custom-modules/build/libs/app/custom-modules.jar"); Assert.assertFalse(modulesJarFile.exists()); CoreTestUtils.callGradleTask( new File(gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/custom-modules/build.gradle"), "jar", new String[0]); // make sure it is created Assert.assertTrue(modulesJarFile.exists()); // pass it as a configuration DeploymentUtils.initAppConfig( new AppConfig.Builder().appClassName(WordCountApp.class.getName()) .customModulesURIs(ImmutableList.of(modulesJarFile.toURI().toString())) .customModulesNames(ImmutableList.of("org.apache.s4.TestListenerModule")).build(), "cluster1", true, "localhost:2181"); if (fork) { forkedS4Node = CoreTestUtils.forkS4Node(new String[] { "-c", "cluster1" }, new ZkClient("localhost:2181"), 10, "cluster1"); } else { S4Node.main(new String[] { "-c", "cluster1" }); } Injector injector = Guice.createInjector( new BaseModule(Resources.getResource("default.s4.base.properties").openStream(), "cluster1"), new DefaultCommModule(Resources.getResource("default.s4.comm.properties").openStream())); Emitter emitter = injector.getInstance(TCPEmitter.class); List<Long> messages = Lists.newArrayList(); for (int i = 0; i < NB_MESSAGES; i++) { messages.add(System.currentTimeMillis()); } ZkClient zkClient = new ZkClient("localhost:2181"); zkClient.create("/test", 0, CreateMode.PERSISTENT); final ZooKeeper zk = CommTestUtils.createZkClient(); final CountDownLatch signalMessagesReceived = new CountDownLatch(1); // watch for last message in test data sequence CoreTestUtils.watchAndSignalCreation( "/test/data" + Strings.padStart(String.valueOf(NB_MESSAGES - 1), 10, '0'), signalMessagesReceived, zk); SerializerDeserializer serDeser = injector.getInstance(SerializerDeserializerFactory.class) .createSerializerDeserializer(Thread.currentThread().getContextClassLoader()); for (Long message : messages) { Event event = new Event(); event.put("message", long.class, message); event.setStreamId("inputStream"); emitter.send(0, serDeser.serialize(event)); } // check sequential nodes in zk with correct data Assert.assertTrue(signalMessagesReceived.await(10, TimeUnit.SECONDS)); List<String> children = zkClient.getChildren("/test"); for (String child : children) { Long data = zkClient.readData("/test/" + child); Assert.assertTrue(messages.contains(data)); } return forkedS4Node; }
From source file:com.buildria.mocking.serializer.ObjectSerializerContext.java
protected boolean isJacksonEnabled() { return Resources.getResource(JACKSON_CLASS) != null; }