List of usage examples for com.google.common.io Files write
public static void write(CharSequence from, File to, Charset charset) throws IOException
From source file:de.flapdoodle.guava.buildsupport.ExtractMarkdownFromCode.java
public static void main(String[] args) { String sourceFileName = args[0]; String destFileName = args[1]; try {/* ww w .j a v a2 s . c o m*/ String markDown = extractMarkdown(sourceFileName); Files.write(markDown, new File(destFileName), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException("could not extract markdown", e); } }
From source file:kn.uni.gis.dataimport.FormatStrangeFlickrFormat.java
License:asdf
public static void main(String[] args) throws IOException { Iterable<String> readLines = filterNulls(concatLines(Files.readLines(new File(INPUT), Charsets.UTF_8))); // BufferedReader reader = Files // .newReader(new File(INPUT), Charsets.UTF_8); // 1,20,12//from w ww .j av a 2s .c o m Files.write(Joiner.on("\n").skipNulls().join(Iterables.transform(readLines, new Function<String, String>() { @Override public String apply(String input) { // System.out.println(input); String[] split = input.split(";"); if (equalss(split[0], "524", "567", "2284", "2720")) { return null; } assertNumbers(split); String asdf = Joiner.on("\t").join(split[0], split[19], split[20], "Z", "M", split[3], ""); System.out.println(asdf); return asdf; } private void assertNumbers(String[] split) { if (!!!split[0].equals("Field1")) { Preconditions.checkArgument(Double.valueOf(split[19].replace(',', '.')) > 13, split[19] + Arrays.toString(split)); Preconditions.checkArgument(Double.valueOf(split[20].replace(',', '.')) > 52, split[20] + Arrays.toString(split)); } } })).replaceAll(",", "."), new File(OUTPUT), Charsets.UTF_8); }
From source file:org.glowroot.agent.ui.sandbox.UiSandboxMain.java
public static void main(String[] args) throws Exception { Container container;// w w w .ja va 2 s.c om File testDir = new File("target"); File configFile = new File(testDir, "config.json"); if (!configFile.exists()) { Files.write("{\"transactions\":{\"profilingIntervalMillis\":100}," + "\"ui\":{\"defaultTransactionType\":\"Sandbox\"}}", configFile, UTF_8); } if (useJavaagent && useGlowrootCentral) { container = new JavaagentContainer(testDir, false, ImmutableList.of("-Dglowroot.agent.id=UI Sandbox", "-Dglowroot.collector.address=localhost:8181")); } else if (useJavaagent) { container = new JavaagentContainer(testDir, true, ImmutableList.<String>of()); } else if (useGlowrootCentral) { container = new LocalContainer(testDir, false, ImmutableMap.of("glowroot.agent.id", "UI Sandbox", "glowroot.collector.address", "localhost:8181")); } else { container = new LocalContainer(testDir, true, ImmutableMap.<String, String>of()); } container.executeNoExpectedTrace(GenerateTraces.class); }
From source file:co.mitro.core.crypto.GenerateKeysToFile.java
/** * @param args/*from w ww . j av a 2s . c o m*/ */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub long start = System.currentTimeMillis(); if (args.length < 2) { throw new Exception("Need 2 args: numKeys outputFileName"); } KeyczarKeyFactory kz = new KeyczarKeyFactory(); final int numKeys = Integer.valueOf(args[0]); List<String> keys = Lists.newLinkedList(); for (int i = 0; i < numKeys; ++i) { System.out.println("generating key " + i); keys.add(kz.generate().toString()); } Gson gson = new Gson(); String out = gson.toJson(keys); Files.write(out, new File(args[1]), Charset.forName("UTF-8")); System.out.println("done in " + (System.currentTimeMillis() - start) + " ms."); }
From source file:org.blackbananacoin.ext.curconvert.MainApp.java
public static void main(String[] args) { String dir = "."; if (args != null) { checkElementIndex(0, args.length); dir = args[0];/*from www. j a v a 2s .co m*/ } final File dirFile = new File(dir); if (!dirFile.exists()) { dirFile.mkdir(); } System.out.println(dirFile.getAbsolutePath()); final File blockchainFile = new File(dirFile, "blockchain_twd.json"); final File twdbtcFile = new File(dirFile, "twdbtc.json"); System.out.println(blockchainFile.getAbsolutePath()); System.out.println(twdbtcFile.getAbsolutePath()); final Charset charset = Charset.forName("UTF-8"); String currencyCode = ExtRateGenServiceImpl.CODE_TWD; // New Taiwan // Dollar final ExtRateGenServiceImpl app = new ExtRateGenServiceImpl(currencyCode); try { app.startRequest(new MyCallback() { public void onResult(Map<GenType, String> jsonStrMap) { try { Files.write(jsonStrMap.get(GenType.BLOCKCHAIN), blockchainFile, charset); Files.write(jsonStrMap.get(GenType.TWDUSD), twdbtcFile, charset); System.out.println("=====Blockchain======"); System.out.println(jsonStrMap.get(GenType.BLOCKCHAIN)); System.out.println("=====TwdUsd======"); System.out.println(jsonStrMap.get(GenType.TWDUSD)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.blackbananacoin.twd2btc.MainApp.java
public static void main(String[] args) { String dir = "."; if (args != null) { checkElementIndex(0, args.length); dir = args[0];//from w w w .j ava 2 s.c o m } final File dirFile = new File(dir); if (!dirFile.exists()) { dirFile.mkdir(); } System.out.println(dirFile.getAbsolutePath()); final File blockchainFile = new File(dirFile, "blockchain_twd.json"); final File twdbtcFile = new File(dirFile, "twdbtc.json"); System.out.println(blockchainFile.getAbsolutePath()); System.out.println(twdbtcFile.getAbsolutePath()); final Charset charset = Charset.forName("UTF-8"); String currencyCode = ExtRateGenServiceImpl.CODE_TWD; // New Taiwan // Dollar final ExtRateGenServiceImpl app = new ExtRateGenServiceImpl(currencyCode); try { app.startRequest(new MyCallback() { public void onResult(Map<GenType, String> jsonStrMap) { try { Files.write(jsonStrMap.get(GenType.BLOCKCHAIN), blockchainFile, charset); //System.out.println("=====Blockchain======"); //System.out.println(jsonStrMap.get(GenType.BLOCKCHAIN)); if (twdbtcFile.exists()) { TwdJsonBuilder jb = new TwdJsonBuilder(); String twdBitStrNew = jsonStrMap.get(GenType.TWDUSD); TwdBit twdBitNew = jb.toTwdBit(twdBitStrNew); try { String twdBitStrOld = Files.readFirstLine(twdbtcFile, charset); TwdBit twdBitOld = jb.toTwdBit(twdBitStrOld); String twdBitStrWithData = jb.buildJsonFromOldTwdBit(twdBitOld, twdBitNew.getUsdtwd(), twdBitNew.getBtcusd()); Files.write(twdBitStrWithData, twdbtcFile, charset); } catch (Exception e) { Files.write(jsonStrMap.get(GenType.TWDUSD), twdbtcFile, charset); } } else { Files.write(jsonStrMap.get(GenType.TWDUSD), twdbtcFile, charset); } //System.out.println("=====TwdUsd======"); //System.out.println(jsonStrMap.get(GenType.TWDUSD)); } catch (IOException e) { e.printStackTrace(); } } }); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.google.bidmanager.api.samples.DownloadLineItems.java
public static void main(String[] args) throws Exception { // Get an authenticated connection to the API. DoubleClickBidManager service = SecurityUtilities.getAPIService(); // Setup any filtering on the API request DownloadLineItemsRequest dliRequest = new DownloadLineItemsRequest(); /* If your download requests times out you may need to filter to reduce the * number of items returned - the commented code below filters on * ADVERTISER_ID, refer to the reference guide at * https://developers.google.com/bid-manager/ for other options. *///from w w w.jav a 2s.co m // .setFilterType("ADVERTISER_ID") // .setFilterIds(Arrays.asList(0L, 1L, 2L)); // Call the API, getting the (filtered) list of line items. dliRequest.setFileSpec("SDF"); DownloadLineItemsResponse dliResponse = service.lineitems().downloadlineitems(dliRequest).execute(); File to = new File("line_items.csv"); Files.write(dliResponse.getLineItems(), to, Charsets.UTF_8); System.out.println("Download complete."); }
From source file:ch.raffael.contracts.processor.cel.parser.CelTestRig.java
public static void main(String[] args) throws Exception { final JFrame frame = new JFrame("Enter Cel Expression"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); final JTextArea source = new JTextArea(); source.setLineWrap(true);//from w ww .j av a2 s. c om source.setWrapStyleWord(true); panel.add(BorderLayout.CENTER, new JScrollPane(source)); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); final JButton parseButton = new JButton("Parse"); panel.add(BorderLayout.SOUTH, parseButton); parseButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new Thread(new Runnable() { public void run() { try { File dest = null; dest = File.createTempFile("cel-testrig-", ".cel"); dest.deleteOnExit(); Files.write(source.getText(), dest, Charset.defaultCharset()); TestRig.main(new String[] { "ch.raffael.contracts.processor.cel.parser.Cel", "clause", "-gui", "-trace", dest.toString() }); dest.delete(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }).start(); //frame.setVisible(false); } }); source.getActionMap().put("parse", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { parseButton.doClick(); } }); source.getActionMap().put("quit", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); source.getInputMap().put(KeyStroke.getKeyStroke("ctrl ENTER"), "parse"); source.getInputMap().put(KeyStroke.getKeyStroke("ESC"), "quit"); frame.setContentPane(panel); frame.pack(); frame.setVisible(true); }
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 va 2 s . 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(); }
From source file:com.github.rinde.gpem17.GenerateParams.java
/** * @param args/*w ww. ja va2 s .c o m*/ * @throws IOException */ public static void main(String[] args) throws IOException { generateTuningExperiments(); for (long seed : SEEDS) { for (Map.Entry<String, String> regexEntry : GPEM17.EXPECTED_REGEXES.entrySet()) { String regex = regexEntry.getKey().replace("\\", "\\\\"); String name = regexEntry.getValue(); int numScensPerGen = 50; int numScensInLastGen = 250; if (name.equals("mixed")) { numScensPerGen = 54; numScensInLastGen = 270; } StringBuilder sb = new StringBuilder("parent.0 = ../gpem17common.params"); sb.append(System.lineSeparator()).append(System.lineSeparator()).append("seed.0 = ").append(seed) .append(System.lineSeparator()).append("eval.num_scenarios_per_gen = ") .append(Integer.toString(numScensPerGen)).append(System.lineSeparator()) .append("eval.num_scenarios_in_last_gen = ").append(Integer.toString(numScensInLastGen)) .append(System.lineSeparator()).append("eval.scenarios_regex = ").append(regex) .append(System.lineSeparator()); File dir = new File("files/config/experiments"); dir.mkdir(); File f = new File(dir, seed + "-" + name + ".params"); Files.write(sb.toString(), f, Charsets.UTF_8); } } }