List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:omakase.printtokens.Program.java
public static void main(String[] args) { if (args.length == 0) { System.err.println("Missing filename argument."); return;//from w w w.j a v a 2 s . c o m } final String filename = args[0]; String source; try { source = Files.toString(new File(filename), Charset.defaultCharset()); } catch (IOException e) { System.err.format("Error '%s' attempting to open file '%s'.\n", e.toString(), filename); return; } SourceFile file = new SourceFile(filename, source); ImmutableList<Token> tokens = Scanner.scanFile(ConsoleErrorReporter.reporter, file); if (!ConsoleErrorReporter.reporter.hadError()) { for (Token token : tokens) { System.out.println(token.toString()); } } }
From source file:omakase.printtree.Program.java
public static void main(String[] args) { if (args.length == 0) { System.err.println("Missing filename argument."); return;/*from www. ja v a 2 s. c om*/ } final String filename = args[0]; String source; try { source = Files.toString(new File(filename), Charset.defaultCharset()); } catch (IOException e) { System.err.format("Error '%s' attempting to open file '%s'.\n", e.toString(), filename); source = null; } if (source == null) { return; } SourceFile file = new SourceFile(filename, source); if (!ConsoleErrorReporter.reporter.hadError()) { ParseTree tree = Parser.parse(ConsoleErrorReporter.reporter, file); ParseTreeWriter writer = new ParseTreeWriter(System.out); writer.visitAny(tree); } }
From source file:org.glowroot.benchmark.ResultFormatter.java
public static void main(String[] args) throws IOException { File resultFile = new File(args[0]); Scores scores = new Scores(); double baselineStartupTime = -1; double glowrootStartupTime = -1; ObjectMapper mapper = new ObjectMapper(); String content = Files.toString(resultFile, Charsets.UTF_8); content = content.replaceAll("\n", " "); ArrayNode results = (ArrayNode) mapper.readTree(content); for (JsonNode result : results) { String benchmark = result.get("benchmark").asText(); benchmark = benchmark.substring(0, benchmark.lastIndexOf('.')); ObjectNode primaryMetric = (ObjectNode) result.get("primaryMetric"); double score = primaryMetric.get("score").asDouble(); if (benchmark.equals(StartupBenchmark.class.getName())) { baselineStartupTime = score; continue; } else if (benchmark.equals(StartupWithGlowrootBenchmark.class.getName())) { glowrootStartupTime = score; continue; }// w ww. j a v a 2 s .co m ObjectNode scorePercentiles = (ObjectNode) primaryMetric.get("scorePercentiles"); double score50 = scorePercentiles.get("50.0").asDouble(); double score95 = scorePercentiles.get("95.0").asDouble(); double score99 = scorePercentiles.get("99.0").asDouble(); double score999 = scorePercentiles.get("99.9").asDouble(); double score9999 = scorePercentiles.get("99.99").asDouble(); double allocatedBytes = getAllocatedBytes(result); if (benchmark.equals(ServletBenchmark.class.getName())) { scores.baselineResponseTimeAvg = score; scores.baselineResponseTime50 = score50; scores.baselineResponseTime95 = score95; scores.baselineResponseTime99 = score99; scores.baselineResponseTime999 = score999; scores.baselineResponseTime9999 = score9999; scores.baselineAllocatedBytes = allocatedBytes; } else if (benchmark.equals(ServletWithGlowrootBenchmark.class.getName())) { scores.glowrootResponseTimeAvg = score; scores.glowrootResponseTime50 = score50; scores.glowrootResponseTime95 = score95; scores.glowrootResponseTime99 = score99; scores.glowrootResponseTime999 = score999; scores.glowrootResponseTime9999 = score9999; scores.glowrootAllocatedBytes = allocatedBytes; } else { throw new AssertionError(benchmark); } } System.out.println(); printScores(scores); if (baselineStartupTime != -1) { System.out.println("STARTUP"); System.out.format("%25s%14s%14s%n", "", "baseline", "glowroot"); printLine("Startup time (avg)", "ms", baselineStartupTime, glowrootStartupTime); } System.out.println(); }
From source file:org.sherlok.utils.SyncNeuroner.java
public static void main(String[] args) throws Exception { String NEURONER_ROOT = "/Users/richarde/git2/neuroNER/"; String sherlokPipelinePath = "config/pipelines/bluima/neuroner/neuroner_0.1.json"; String rutaPipelinePath = NEURONER_ROOT + "script/neuroner/NeuroNER.ruta"; // update script PipelineDef p = parsePipeline(Files.toString(new File(sherlokPipelinePath), UTF_8)); List<String> rutaLines = readLines(new File(rutaPipelinePath), UTF_8); p.setScriptLines(rutaLines);/*from w ww . j av a 2 s. co m*/ FileBased.write(new File(sherlokPipelinePath), p); // write back // copy NeuroNER resources copyDirectory(new File(NEURONER_ROOT + "resources/bluima/neuroner"), new File("config/resources/bluima/neuroner")); System.out.println("Done :-)"); }
From source file:com.google.bidmanager.api.samples.UploadLineItems.java
public static void main(String[] args) throws Exception { // Get an authenticated connection to the API. DoubleClickBidManager service = SecurityUtilities.getAPIService(); // Get the line items from the csv file. File from = new File("line_items.csv"); String lineItems = Files.toString(from, Charsets.UTF_8); // Set up the request details including the line items. UploadLineItemsRequest uliContent = new UploadLineItemsRequest().setDryRun(DRYRUN).setLineItems(lineItems); // Call the API, passing in the request details. UploadLineItemsResponse uliResponse = service.lineitems().uploadlineitems(uliContent).execute(); // Check for errors. List<String> errorList = uliResponse.getUploadStatus().getErrors(); if (errorList == null) { System.out.println("Upload Successful"); } else {//ww w . ja v a 2 s .co m for (String e : errorList) { System.out.println(e); } } }
From source file:ruke.vrj.Main.java
/** * Starting point, lets do some magic.//from w w w . jav a 2 s.c o m * * @param args Arguments */ public static void main(String[] args) { final Compiler compiler = new Compiler(); try { for (final String arg : args) { final String toCompile = Files.toString(new File(arg), Charsets.UTF_8); final String compiled = compiler.compile(toCompile); final long start = System.nanoTime(); if (compiler.getResults().isEmpty()) { System.out.println(compiled); } else { System.out.println(compiler.getResults()); } System.out.println("Compiled in " + MILLISECONDS.convert(System.nanoTime() - start, NANOSECONDS) + " milliseconds"); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jclouds.examples.google.computeengine.DeleteServer.java
/** * The first argument (args[0]) must be your service account email address * The second argument (args[1]) must a path to your service account * private key PEM file (without a password). *///from w ww. ja va 2 s . c om public static void main(String[] args) throws IOException { String key = Files.toString(new File(args[1]), Charset.defaultCharset()); DeleteServer deleteServer = new DeleteServer(args[0], key); try { deleteServer.deleteServer(); } catch (Exception e) { e.printStackTrace(); } finally { deleteServer.close(); } }
From source file:org.apache.drill.exec.RunRootExec.java
public static void main(String args[]) throws Exception { String path = args[0];/*w w w . ja va 2s .co m*/ int iterations = Integer.parseInt(args[1]); Drillbit bit = new Drillbit(c, RemoteServiceSet.getLocalServiceSet()); bit.run(); DrillbitContext bitContext = bit.getContext(); PhysicalPlanReader reader = bitContext.getPlanReader(); PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(new File(path), Charsets.UTF_8)); FunctionImplementationRegistry registry = bitContext.getFunctionImplementationRegistry(); FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), null, registry); SimpleRootExec exec; for (int i = 0; i < iterations; i++) { Stopwatch w = new Stopwatch().start(); System.out.println("STARTITER:" + i); exec = new SimpleRootExec( ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while (exec.next()) { for (ValueVector v : exec) { v.clear(); } } System.out.println("ENDITER: " + i); System.out.println("TIME: " + w.elapsed(TimeUnit.MILLISECONDS) + "ms"); exec.close(); } context.close(); bit.close(); }
From source file:net.liuxuan.device.VACVBS.VACVBSInfoMetaData.java
public static void main(String[] args) throws IOException { // VACVBSMetaData meta = new VACVBSMetaData(); // meta.HP = 100; // meta.Humidity = 20; // meta.LP = 200; // meta.Temprature = 100; // meta.Time = 3; //// meta.date1=""; // meta.date1 = new Date(); // meta.num = 0; // meta.reserved1 = 0; ///*from w w w. j av a2 s .c o m*/ Gson gson = new Gson(); // String a = gson.toJson(meta); // System.out.println(a); // String b = "{ \"num\":\"0\", \"HP\":\"0\", \"LP\":\"10\", \"Humidity\":\"39\", \"Temprature\":\"23.5\", \"date1\":\"2014-8-16 16:27:54 \", \"Time\":\"6\"}"; // VACVBSMetaData d =gson.fromJson(b, VACVBSMetaData.class); // System.out.println(d.LP); // System.out.println(d.date1); File filea = new File( "F:\\MosesData\\Desktop\\?\\VAC-VBS data\\VBS\\\\bbb.VBSGTR.txt"); String fileContent = Files.toString(filea, Charsets.ISO_8859_1); // System.out.println(fileContent); VACVBSInfoMetaData imd = gson.fromJson(fileContent, VACVBSInfoMetaData.class); System.out.println(imd.Device); System.out.println(imd.datas.size()); System.out.println(imd.datas.get(0).date1); // JsonParser parser = new JsonParser(); // JsonElement je = parser.parse(fileContent); // // JsonArray array = je.getAsJsonArray(); // System.out.println(array.size()); }
From source file:org.t3as.metamap.cmdline.Main.java
public static void main(final String[] args) throws Exception { final CmdOpts opts = new CmdOpts(); JCommander jc = null;/*from ww w . ja v a 2s. co m*/ try { jc = new JCommander(opts, args); } catch (final Exception e) { System.err.println("Could not parse the options: " + e.getMessage()); System.exit(1); } if (opts.showUsage) { jc.usage(); System.exit(0); } // sanitise the input final File sanitised = File.createTempFile("metamap-sanitised-", ".txt"); final String s = Files.toString(opts.input, UTF_8); Files.write(s, sanitised, UTF_8); // process the data with MetaMap final MetaMap metaMap = new MetaMap(opts.publicMm, DEFAULT_MM_OPTIONS); if (!metaMap.process(sanitised, opts.output)) { System.err.println("MetaMap processing failed, aborting."); System.exit(1); } //noinspection ResultOfMethodCallIgnored sanitised.delete(); }