List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:com.zenika.doclipser.api.ReadPropertiesWithGuava.java
public final static void main(final String[] args) { final URL url = Resources.getResource(Constants.PROPERTY_FILE_NAME); final ByteSource byteSource = Resources.asByteSource(url); final Properties properties = new Properties(); InputStream inputStream = null; try {//ww w . j ava 2s . c om inputStream = byteSource.openBufferedStream(); properties.load(inputStream); properties.list(System.out); } catch (final IOException ioException) { ioException.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (final IOException ioException) { ioException.printStackTrace(); } } } }
From source file:ui.main.console.ConsoleMain.java
public static void main(String[] args) throws IOException { CompilerController compiler = new CompilerController(new ShellConsole()); URL url = Resources.getResource("tests/memoTest1.txt"); String source = Resources.toString(url, Charsets.UTF_8); compiler.interpret(source);/* ww w .j a v a2 s . co m*/ }
From source file:se.kth.karamel.client.api.Driver.java
public static void main(String[] args) throws IOException, KaramelException, InterruptedException { //Karamel will read your ssh-key pair from the default location (~/.ssh/id_rsa and ~/.ssh/id_rsa/id_rsa.pub) in //the unix-based systems. It uses your key-pair for ec2, so please make sure you have them provided before start //running this program KaramelApi api = new KaramelApiImpl(); //give your own yaml file String ymlString = Resources.toString( Resources.getResource("se/kth/karamel/client/model/test-definitions/hiway.yml"), Charsets.UTF_8); //since api works with json you will need to convert your yaml to json String json = api.yamlToJson(ymlString); //pass in your ec2 credentials here, Ec2Credentials credentials = new Ec2Credentials(); credentials.setAccessKey("<ec2-accoun-id>"); credentials.setSecretKey("<ec2-access-key>"); if (!api.updateEc2CredentialsIfValid(credentials)) throw new IllegalThreadStateException("Ec2 credentials is not valid"); //this is an async call, you will need to pull status of your cluster periodically with the forthcoming call api.startCluster(json);//ww w.j a v a 2s. c o m long ms1 = System.currentTimeMillis(); while (ms1 + 6000000 > System.currentTimeMillis()) { //the name of the cluster should be equal to the one you specified in your yaml file String clusterStatus = api.getClusterStatus("hiway"); logger.debug(clusterStatus); Thread.currentThread().sleep(60000); } }
From source file:com.google.template.soy.examples.SimpleUsage.java
/** * Prints the generated HTML to stdout./*from w w w. j a va 2 s . c om*/ * @param args Not used. */ public static void main(String[] args) { // Compile the template. SoyFileSet sfs = SoyFileSet.builder().add(Resources.getResource("simple.soy")).build(); SoyTofu tofu = sfs.compileToTofu(); // Example 1. writeExampleHeader(); System.out.println(tofu.newRenderer("soy.examples.simple.helloWorld").render()); // Create a namespaced tofu object to make calls more concise. SoyTofu simpleTofu = tofu.forNamespace("soy.examples.simple"); // Example 2. writeExampleHeader(); System.out.println(simpleTofu.newRenderer(".helloName").setData(new SoyMapData("name", "Ana")).render()); // Example 3. writeExampleHeader(); System.out.println(simpleTofu.newRenderer(".helloNames") .setData(new SoyMapData("names", new SoyListData("Bob", "Cid", "Dee"))).render()); }
From source file:util.mybatis.CodeGeneratorRuner.java
public static void main(String[] args) throws Exception { boolean overwrite = true; String generatorConfig = CodeGeneratorRuner.class.getClassLoader().getResource("generatorConfig.xml") .getFile();/* ww w. ja v a 2s .c om*/ URL url = Resources.getResource("generatorConfig.xml"); URLConnection openConnection = url.openConnection(); InputStream inputStream = openConnection.getInputStream(); OutputFormat format = new OutputFormat(); format.setEncoding("UTF-8"); List<String> warnings = new ArrayList<String>(); Log.print("???," + generatorConfig); // File conifgFile = new File(url); ConfigurationParser configurationParser = new ConfigurationParser(warnings); Configuration configuration = configurationParser .parseConfiguration(new InputStreamReader(inputStream, "UTF-8")); DefaultShellCallback shellCallback = new DefaultShellCallback(overwrite); MyBatisGenerator batisGenerator = new MyBatisGenerator(configuration, shellCallback, warnings); batisGenerator.generate(new CodeProgressCallback()); }
From source file:org.thingsboard.client.tools.MqttSslClient.java
public static void main(String[] args) { try {/*from www . j av a 2s .co m*/ URL ksUrl = Resources.getResource(KEY_STORE_FILE); File ksFile = new File(ksUrl.toURI()); URL tsUrl = Resources.getResource(KEY_STORE_FILE); File tsFile = new File(tsUrl.toURI()); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); KeyStore trustStore = KeyStore.getInstance(JKS); char[] ksPwd = new char[] { 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x5F, 0x6B, 0x73, 0x5F, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64 }; trustStore.load(new FileInputStream(tsFile), ksPwd); tmf.init(trustStore); KeyStore ks = KeyStore.getInstance(JKS); ks.load(new FileInputStream(ksFile), ksPwd); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); char[] clientPwd = new char[] { 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x5F, 0x6B, 0x65, 0x79, 0x5F, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64 }; kmf.init(ks, clientPwd); KeyManager[] km = kmf.getKeyManagers(); TrustManager[] tm = tmf.getTrustManagers(); SSLContext sslContext = SSLContext.getInstance(TLS); sslContext.init(km, tm, null); MqttConnectOptions options = new MqttConnectOptions(); options.setSocketFactory(sslContext.getSocketFactory()); MqttAsyncClient client = new MqttAsyncClient(MQTT_URL, CLIENT_ID); client.connect(options); Thread.sleep(3000); MqttMessage message = new MqttMessage(); message.setPayload("{\"key1\":\"value1\", \"key2\":true, \"key3\": 3.0, \"key4\": 4}".getBytes()); client.publish("v1/devices/me/telemetry", message); client.disconnect(); log.info("Disconnected"); System.exit(0); } catch (Exception e) { log.error("Unexpected exception occurred in MqttSslClient", e); } }
From source file:org.apache.drill.exec.planner.logical.StorageEngines.java
public static void main(String[] args) throws Exception { DrillConfig config = DrillConfig.create(); String data = Resources.toString(Resources.getResource("storage-engines.json"), Charsets.UTF_8); StorageEngines se = config.getMapper().readValue(data, StorageEngines.class); System.out.println(se);/*from w ww.j a v a2 s .c o m*/ }
From source file:io.soabase.example.MockDatabase.java
@SuppressWarnings("ParameterCanBeLocal") public static void main(String[] args) throws Exception { if (!Boolean.getBoolean("debug")) { OutputStream nullOut = new OutputStream() { @Override/* w w w . j a v a2 s . com*/ public void write(int b) throws IOException { } }; System.setOut(new PrintStream(nullOut)); } args = new String[] { "--database.0", "mem:test", "--dbname.0", "xdb", "--port", "10064" }; Server.main(args); SqlSession session; try (InputStream stream = Resources.getResource("example-mybatis.xml").openStream()) { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(stream); Configuration mybatisConfiguration = sqlSessionFactory.getConfiguration(); mybatisConfiguration.addMapper(AttributeEntityMapper.class); session = sqlSessionFactory.openSession(true); } AttributeEntityMapper mapper = session.getMapper(AttributeEntityMapper.class); mapper.createTable(); mapper.insert(new AttributeEntity("test", "global")); mapper.insert(new AttributeEntity("test2", "hello", "one")); mapper.insert(new AttributeEntity("test2", "goodbye", "two")); List<AttributeEntity> attributeEntities = mapper.selectAll(); System.out.println(attributeEntities); System.out.println("Running..."); Thread.currentThread().join(); }
From source file:org.apache.drill.exec.planner.logical.StoragePlugins.java
public static void main(String[] args) throws Exception { DrillConfig config = DrillConfig.create(); String data = Resources.toString(Resources.getResource("storage-engines.json"), Charsets.UTF_8); StoragePlugins se = config.getMapper().readValue(data, StoragePlugins.class); ByteArrayOutputStream os = new ByteArrayOutputStream(); config.getMapper().writeValue(System.out, se); config.getMapper().writeValue(os, se); se = config.getMapper().readValue(new ByteArrayInputStream(os.toByteArray()), StoragePlugins.class); System.out.println(se);/* w ww. ja va 2s .co m*/ }
From source file:org.apache.drill.exec.compile.bytecode.ReplaceMethodInvoke.java
public static void main(String[] args) throws Exception { final String k2 = "org/apache/drill/Pickle.class"; final URL url = Resources.getResource(k2); final byte[] clazz = Resources.toByteArray(url); final ClassReader cr = new ClassReader(clazz); final ClassWriter cw = writer(); final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out)); final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true); cr.accept(v2, ClassReader.EXPAND_FRAMES);//| ClassReader.SKIP_DEBUG); final byte[] output = cw.toByteArray(); Files.write(output, new File("/src/scratch/bytes/S.class")); check(output);/*from ww w . java2 s. c o m*/ final DrillConfig c = DrillConfig.forClient(); final SystemOptionManager m = new SystemOptionManager(c, new LocalPStoreProvider(c)); m.init(); try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) { ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output); Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch"); clz.getMethod("x").invoke(null); } }