List of usage examples for com.google.common.io Resources toString
public static String toString(URL url, Charset charset) throws IOException
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);//w w w .j ava2s . c o 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);/*from w w 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.xemantic.tadedon.gwt.field.rebind.StringTemplateViewer.java
public static void main(String[] args) throws IOException { URL url = UiFieldAccessorGenerator.class.getResource("UiFieldAccessor.template"); String templateFile = Resources.toString(url, Charsets.UTF_8); StringTemplate template = new StringTemplate(templateFile, DefaultTemplateLexer.class); template.setAttribute("year", Calendar.getInstance().get(Calendar.YEAR)); template.setAttribute("date", new Date()); template.setAttribute("package", "com.example"); template.setAttribute("className", "UiFieldAccessorDemo_Impl"); template.setAttribute("ownerType", "FooOwner"); template.setAttribute("fields", Arrays.asList("foo", "bar")); System.out.println(template.toString()); }
From source file:org.apache.niolex.oauth.OAuthServer.java
public static void main(String[] args) throws Exception { SpringApplication.run(OAuthServer.class, args); System.out.println("OAuthServer is Up!"); System.out.println(Resources.toString(OAuthServer.class.getResource("/logo.txt"), Charsets.UTF_8)); }
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 w w . j ava 2 s . c om*/ }
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 . j a v a2s .co m }
From source file:org.bitcoinj_extra.tools.BuildCheckpoints.java
public static void main(String[] args) throws Exception { BriefLogFormatter.initWithSilentBitcoinJ(); OptionParser parser = new OptionParser(); parser.accepts("help"); OptionSpec<NetworkEnum> netFlag = parser.accepts("net").withRequiredArg().ofType(NetworkEnum.class) .defaultsTo(NetworkEnum.MAIN); parser.accepts("peer").withRequiredArg(); OptionSpec<Integer> daysFlag = parser.accepts("days").withRequiredArg().ofType(Integer.class) .defaultsTo(30);/* w w w .ja va 2s .c o m*/ OptionSet options = parser.parse(args); if (options.has("help")) { System.out.println(Resources.toString(BuildCheckpoints.class.getResource("build-checkpoints-help.txt"), Charsets.UTF_8)); return; } final String suffix; switch (netFlag.value(options)) { case MAIN: case PROD: params = MainNetParams.get(); suffix = ""; break; case TEST: params = TestNet3Params.get(); suffix = "-testnet"; break; case REGTEST: params = RegTestParams.get(); suffix = "-regtest"; break; default: throw new RuntimeException("Unreachable."); } final InetAddress ipAddress; if (options.has("peer")) { String peerFlag = (String) options.valueOf("peer"); try { ipAddress = InetAddress.getByName(peerFlag); } catch (UnknownHostException e) { System.err.println( "Could not understand peer domain name/IP address: " + peerFlag + ": " + e.getMessage()); System.exit(1); return; } } else { ipAddress = InetAddress.getLocalHost(); } final PeerAddress peerAddress = new PeerAddress(ipAddress, params.getPort()); // Sorted map of block height to StoredBlock object. final TreeMap<Integer, StoredBlock> checkpoints = new TreeMap<Integer, StoredBlock>(); // Configure bitcoinj_extra to fetch only headers, not save them to disk, connect to a local fully synced/validated // node and to save block headers that are on interval boundaries, as long as they are <1 month old. final BlockStore store = new MemoryBlockStore(params); final BlockChain chain = new BlockChain(params, store); final PeerGroup peerGroup = new PeerGroup(params, chain); System.out.println("Connecting to " + peerAddress + "..."); peerGroup.addAddress(peerAddress); long now = new Date().getTime() / 1000; peerGroup.setFastCatchupTimeSecs(now); final long timeAgo = now - (86400 * options.valueOf(daysFlag)); System.out.println("Checkpointing up to " + Utils.dateTimeFormat(timeAgo * 1000)); chain.addNewBestBlockListener(Threading.SAME_THREAD, new NewBestBlockListener() { @Override public void notifyNewBestBlock(StoredBlock block) throws VerificationException { int height = block.getHeight(); if (height % params.getInterval() == 0 && block.getHeader().getTimeSeconds() <= timeAgo) { System.out.println(String.format("Checkpointing block %s at height %d, time %s", block.getHeader().getHash(), block.getHeight(), Utils.dateTimeFormat(block.getHeader().getTime()))); checkpoints.put(height, block); } } }); peerGroup.start(); peerGroup.downloadBlockChain(); checkState(checkpoints.size() > 0); final File plainFile = new File("checkpoints" + suffix); final File textFile = new File("checkpoints" + suffix + ".txt"); // Write checkpoint data out. writeBinaryCheckpoints(checkpoints, plainFile); writeTextualCheckpoints(checkpoints, textFile); peerGroup.stop(); store.close(); // Sanity check the created files. sanityCheck(plainFile, checkpoints.size()); sanityCheck(textFile, checkpoints.size()); }
From source file:org.guldenj.tools.BuildCheckpoints.java
public static void main(String[] args) throws Exception { BriefLogFormatter.initWithSilentGuldenJ(); OptionParser parser = new OptionParser(); parser.accepts("help"); OptionSpec<NetworkEnum> netFlag = parser.accepts("net").withRequiredArg().ofType(NetworkEnum.class) .defaultsTo(NetworkEnum.MAIN); parser.accepts("peer").withRequiredArg(); OptionSpec<Integer> daysFlag = parser.accepts("days").withRequiredArg().ofType(Integer.class).defaultsTo(5); OptionSet options = parser.parse(args); if (options.has("help")) { System.out.println(Resources.toString(BuildCheckpoints.class.getResource("build-checkpoints-help.txt"), Charsets.UTF_8));/*www.j a v a2 s . c o m*/ return; } final String suffix; switch (netFlag.value(options)) { case MAIN: case PROD: params = MainNetParams.get(); suffix = ""; break; case TEST: params = TestNet3Params.get(); suffix = "-testnet"; break; case REGTEST: params = RegTestParams.get(); suffix = "-regtest"; break; default: throw new RuntimeException("Unreachable."); } // Configure guldenj to fetch only headers, not save them to disk, connect to a local fully synced/validated // node and to save block headers that are on interval boundaries, as long as they are <1 month old. final BlockStore store = new MemoryBlockStore(params); final BlockChain chain = new BlockChain(params, store); final PeerGroup peerGroup = new PeerGroup(params, chain); final InetAddress ipAddress; // DNS discovery can be used for some networks boolean networkHasDnsSeeds = params.getDnsSeeds() != null; if (options.has("peer")) { // use peer provided in argument String peerFlag = (String) options.valueOf("peer"); try { ipAddress = InetAddress.getByName(peerFlag); startPeerGroup(peerGroup, ipAddress); } catch (UnknownHostException e) { System.err.println( "Could not understand peer domain name/IP address: " + peerFlag + ": " + e.getMessage()); System.exit(1); return; } } /*else if (networkHasDnsSeeds) { // for PROD and TEST use a peer group discovered with dns peerGroup.setUserAgent("PeerMonitor", "1.0"); peerGroup.setMaxConnections(20); peerGroup.addPeerDiscovery(new DnsDiscovery(params)); peerGroup.start(); // Connect to at least 4 peers because some may not support download Future<List<Peer>> future = peerGroup.waitForPeers(4); System.out.println("Connecting to " + params.getId() + ", timeout 20 seconds..."); // throw timeout exception if we can't get peers future.get(20, SECONDS); }*/ else { // try localhost ipAddress = InetAddress.getLocalHost(); startPeerGroup(peerGroup, ipAddress); } // Sorted map of block height to StoredBlock object. final TreeMap<Integer, StoredBlock> checkpoints = new TreeMap<Integer, StoredBlock>(); long now = new Date().getTime() / 1000; peerGroup.setFastCatchupTimeSecs(now); final long timeAgo = now - (86400 * options.valueOf(daysFlag)); System.out.println("Checkpointing up to " + Utils.dateTimeFormat(timeAgo * 1000)); chain.addNewBestBlockListener(Threading.SAME_THREAD, new NewBestBlockListener() { @Override public void notifyNewBestBlock(StoredBlock block) throws VerificationException { int height = block.getHeight(); if (height % params.getInterval() == 0 && block.getHeader().getTimeSeconds() <= timeAgo) { System.out.println(String.format("Checkpointing block %s at height %d, time %s", block.getHeader().getHash(), block.getHeight(), Utils.dateTimeFormat(block.getHeader().getTime()))); checkpoints.put(height, block); } } }); peerGroup.downloadBlockChain(); checkState(checkpoints.size() > 0); final File plainFile = new File("checkpoints" + suffix); final File textFile = new File("checkpoints" + suffix + ".txt"); // Write checkpoint data out. writeBinaryCheckpoints(checkpoints, plainFile); writeTextualCheckpoints(checkpoints, textFile); peerGroup.stop(); store.close(); // Sanity check the created files. //sanityCheck(plainFile, checkpoints.size()); //sanityCheck(textFile, checkpoints.size()); }
From source file:org.bitcoinj.tools.BuildCheckpoints.java
public static void main(String[] args) throws Exception { BriefLogFormatter.initWithSilentBitcoinJ(); OptionParser parser = new OptionParser(); parser.accepts("help"); OptionSpec<NetworkEnum> netFlag = parser.accepts("net").withRequiredArg().ofType(NetworkEnum.class) .defaultsTo(NetworkEnum.MAIN); parser.accepts("peer").withRequiredArg(); OptionSpec<Integer> daysFlag = parser.accepts("days").withRequiredArg().ofType(Integer.class) .defaultsTo(30);/*from w w w . j a v a 2s. c o m*/ OptionSet options = parser.parse(args); if (options.has("help")) { System.out.println(Resources.toString(BuildCheckpoints.class.getResource("build-checkpoints-help.txt"), Charsets.UTF_8)); return; } final String suffix; switch (netFlag.value(options)) { case MAIN: case PROD: params = MainNetParams.get(); suffix = ""; break; case TEST: params = TestNet3Params.get(); suffix = "-testnet"; break; case REGTEST: params = RegTestParams.get(); suffix = "-regtest"; break; default: throw new RuntimeException("Unreachable."); } // Configure bitcoinj to fetch only headers, not save them to disk, connect to a local fully synced/validated // node and to save block headers that are on interval boundaries, as long as they are <1 month old. final BlockStore store = new MemoryBlockStore(params); final BlockChain chain = new BlockChain(params, store); final PeerGroup peerGroup = new PeerGroup(params, chain); final InetAddress ipAddress; // DNS discovery can be used for some networks boolean networkHasDnsSeeds = params.getDnsSeeds() != null; if (options.has("peer")) { // use peer provided in argument String peerFlag = (String) options.valueOf("peer"); try { ipAddress = InetAddress.getByName(peerFlag); startPeerGroup(peerGroup, ipAddress); } catch (UnknownHostException e) { System.err.println( "Could not understand peer domain name/IP address: " + peerFlag + ": " + e.getMessage()); System.exit(1); return; } } else if (networkHasDnsSeeds) { // for PROD and TEST use a peer group discovered with dns peerGroup.setUserAgent("PeerMonitor", "1.0"); peerGroup.setMaxConnections(20); peerGroup.addPeerDiscovery(new DnsDiscovery(params)); peerGroup.start(); // Connect to at least 4 peers because some may not support download Future<List<Peer>> future = peerGroup.waitForPeers(4); System.out.println("Connecting to " + params.getId() + ", timeout 20 seconds..."); // throw timeout exception if we can't get peers future.get(20, SECONDS); } else { // try localhost ipAddress = InetAddress.getLocalHost(); startPeerGroup(peerGroup, ipAddress); } // Sorted map of block height to StoredBlock object. final TreeMap<Integer, StoredBlock> checkpoints = new TreeMap<Integer, StoredBlock>(); long now = new Date().getTime() / 1000; peerGroup.setFastCatchupTimeSecs(now); final long timeAgo = now - (86400 * options.valueOf(daysFlag)); System.out.println("Checkpointing up to " + Utils.dateTimeFormat(timeAgo * 1000)); chain.addNewBestBlockListener(Threading.SAME_THREAD, new NewBestBlockListener() { @Override public void notifyNewBestBlock(StoredBlock block) throws VerificationException { int height = block.getHeight(); if (height % params.getInterval() == 0 && block.getHeader().getTimeSeconds() <= timeAgo) { System.out.println(String.format("Checkpointing block %s at height %d, time %s", block.getHeader().getHash(), block.getHeight(), Utils.dateTimeFormat(block.getHeader().getTime()))); checkpoints.put(height, block); } } }); peerGroup.downloadBlockChain(); checkState(checkpoints.size() > 0); final File plainFile = new File("checkpoints" + suffix); final File textFile = new File("checkpoints" + suffix + ".txt"); // Write checkpoint data out. writeBinaryCheckpoints(checkpoints, plainFile); writeTextualCheckpoints(checkpoints, textFile); peerGroup.stop(); store.close(); // Sanity check the created files. sanityCheck(plainFile, checkpoints.size()); sanityCheck(textFile, checkpoints.size()); }
From source file:org.litecoinj.tools.BuildCheckpoints.java
public static void main(String[] args) throws Exception { BriefLogFormatter.initWithSilentBitcoinJ(); OptionParser parser = new OptionParser(); parser.accepts("help"); OptionSpec<NetworkEnum> netFlag = parser.accepts("net").withRequiredArg().ofType(NetworkEnum.class) .defaultsTo(NetworkEnum.MAIN); parser.accepts("peer").withRequiredArg(); OptionSpec<Integer> daysFlag = parser.accepts("days").withRequiredArg().ofType(Integer.class) .defaultsTo(30);// w w w . j a va 2s .c om OptionSet options = parser.parse(args); if (options.has("help")) { System.out.println(Resources.toString(BuildCheckpoints.class.getResource("build-checkpoints-help.txt"), Charsets.UTF_8)); return; } final String suffix; switch (netFlag.value(options)) { case MAIN: case PROD: params = MainNetParams.get(); suffix = ""; break; case TEST: params = TestNet3Params.get(); suffix = "-testnet"; break; case REGTEST: params = RegTestParams.get(); suffix = "-regtest"; break; default: throw new RuntimeException("Unreachable."); } // Configure litecoinj to fetch only headers, not save them to disk, connect to a local fully synced/validated // node and to save block headers that are on interval boundaries, as long as they are <1 month old. final BlockStore store = new MemoryBlockStore(params); final BlockChain chain = new BlockChain(params, store); final PeerGroup peerGroup = new PeerGroup(params, chain); final InetAddress ipAddress; // DNS discovery can be used for some networks boolean networkHasDnsSeeds = params.getDnsSeeds() != null; if (options.has("peer")) { // use peer provided in argument String peerFlag = (String) options.valueOf("peer"); try { ipAddress = InetAddress.getByName(peerFlag); startPeerGroup(peerGroup, ipAddress); } catch (UnknownHostException e) { System.err.println( "Could not understand peer domain name/IP address: " + peerFlag + ": " + e.getMessage()); System.exit(1); return; } } else if (networkHasDnsSeeds) { // for PROD and TEST use a peer group discovered with dns peerGroup.setUserAgent("PeerMonitor", "1.0"); peerGroup.setMaxConnections(20); peerGroup.addPeerDiscovery(new DnsDiscovery(params)); peerGroup.start(); // Connect to at least 4 peers because some may not support download Future<List<Peer>> future = peerGroup.waitForPeers(4); System.out.println("Connecting to " + params.getId() + ", timeout 20 seconds..."); // throw timeout exception if we can't get peers future.get(20, SECONDS); } else { // try localhost ipAddress = InetAddress.getLocalHost(); startPeerGroup(peerGroup, ipAddress); } // Sorted map of block height to StoredBlock object. final TreeMap<Integer, StoredBlock> checkpoints = new TreeMap<Integer, StoredBlock>(); long now = new Date().getTime() / 1000; peerGroup.setFastCatchupTimeSecs(now); final long timeAgo = now - (86400 * options.valueOf(daysFlag)); System.out.println("Checkpointing up to " + Utils.dateTimeFormat(timeAgo * 1000)); chain.addNewBestBlockListener(Threading.SAME_THREAD, new NewBestBlockListener() { @Override public void notifyNewBestBlock(StoredBlock block) throws VerificationException { int height = block.getHeight(); if (height % params.getInterval() == 0 && block.getHeader().getTimeSeconds() <= timeAgo) { System.out.println(String.format("Checkpointing block %s at height %d, time %s", block.getHeader().getHash(), block.getHeight(), Utils.dateTimeFormat(block.getHeader().getTime()))); checkpoints.put(height, block); } } }); peerGroup.downloadBlockChain(); checkState(checkpoints.size() > 0); final File plainFile = new File("checkpoints" + suffix); final File textFile = new File("checkpoints" + suffix + ".txt"); // Write checkpoint data out. writeBinaryCheckpoints(checkpoints, plainFile); writeTextualCheckpoints(checkpoints, textFile); peerGroup.stop(); store.close(); // Sanity check the created files. sanityCheck(plainFile, checkpoints.size()); sanityCheck(textFile, checkpoints.size()); }