List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data, String encoding) throws IOException
From source file:de.blizzy.documentr.markdown.macro.GroovyMacroScannerTest.java
@Before public void setUp() throws IOException { File dataDir = tempDir.getRoot(); when(settings.getDocumentrDataDir()).thenReturn(dataDir); macrosDir = new File(dataDir, GroovyMacroScanner.MACROS_DIR_NAME); File macroFile = new File(macrosDir, MACRO_NAME + ".groovy"); //$NON-NLS-1$ FileUtils.writeStringToFile(macroFile, MACRO, Charsets.UTF_8); scanner.init();/*from w w w . j ava2 s . c om*/ }
From source file:com.puzzle.module.send.excutor.MessageSendExcutor.java
public void excute(File xml) { KafkaProducerClient client = null;//from ww w . j a va2 s .co m try { String content = FileUtils.readFileToString(xml, "UTF-8"); XmlCheckResult checkResult = xmlCheck.isValid(content); if (!checkResult.isValid) {// FileUtils.copyFileToDirectory(xml, new File(FileDto.getSingleInstance().errorPath), true); log.error(xml.getAbsolutePath() + ""); return; } boolean tr = true; if (content.indexOf("<CEB625Message") != -1 || content.indexOf("<CEB623Message") != -1 || content.indexOf("<CEB711Message") != -1 || content.indexOf("<CEB513Message") != -1) {//? String signedXml = SignXml.sign2(content); if (signedXml == null || signedXml.equals("")) { return; } File signFile = new File(FileDto.getSingleInstance().fileSignPath, "???-" + DateUtil.getCurrDateMM2() + xml.getName()); FileUtils.writeStringToFile(signFile, signedXml, "UTF-8"); if (FileDto.getSingleInstance().sendCusisSelected) { client = KafkaProducerClient.getSingletonInstance(); client.send(FileDto.getSingleInstance().cusSendTopic, signedXml); QueueUtils.sendSignTable.offer(new JtableMessageDto(signFile.getAbsolutePath(), DateUtil.getFormatDateTime(new Date()))); log.info(xml.getName() + "???"); } } else { String splitXml = SpliteXml.splite(content); if (splitXml == null) { return; } log.info(xml.getName() + ""); splitXml = SignXml.sign(splitXml);// ???? if (splitXml == null) { log.info("?>>>>??"); return; } File signFile = new File(FileDto.getSingleInstance().fileSignPath, "???-" + DateUtil.getCurrDateMM2() + xml.getName()); FileUtils.writeStringToFile(signFile, splitXml, "UTF-8"); // if (FileDto.getSingleInstance().sendCusisSelected) { client = KafkaProducerClient.getSingletonInstance(); client.send(FileDto.getSingleInstance().cusSendTopic, splitXml); QueueUtils.sendSignTable.offer(new JtableMessageDto(signFile.getAbsolutePath(), DateUtil.getFormatDateTime(new Date()))); log.info(xml.getName() + "???"); } if (FileDto.getSingleInstance().sendCiqisSelected) { client = KafkaProducerClient.getSingletonInstance(); client.send(FileDto.getSingleInstance().sendTpoic, content);//??? QueueUtils.sendTable1.offer( new JtableMessageDto(xml.getAbsolutePath(), DateUtil.getFormatDateTime(new Date()))); log.info(xml.getName() + "???"); } } } catch (Exception e) { e.printStackTrace(); if (client != null) { client.close(); } } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.svmlib.SVMLibExperimentRunner.java
public Set<SinglePrediction> runSingleFold(File testFile, List<File> trainingFiles) throws IOException { // concat the training files into a single file StringBuilder allTrainingFilesContent = new StringBuilder(); for (File f : trainingFiles) { allTrainingFilesContent.append(FileUtils.readFileToString(f, "utf-8")); }/*from w w w .j a v a2 s. c o m*/ // temporary training file from all training files File trainingFile = File.createTempFile("training", ".libsvm.txt"); FileUtils.writeStringToFile(trainingFile, allTrainingFilesContent.toString(), "utf-8"); File tempModelFile = File.createTempFile(testFile.getName(), ".model"); System.out.println("Training..."); // train trainSvm(trainingFile, tempModelFile); System.out.println("Done."); File tempModelPredictions = File.createTempFile("test_pred", ".txt"); testSvm(testFile, tempModelFile, tempModelPredictions); // now load predictions and match them to the gold labels Set<SinglePrediction> predictions = loadPredictions(testFile, tempModelPredictions); System.out.println("Wrong predictions"); for (SinglePrediction sp : predictions) { if (!sp.getGold().equals(sp.getPrediction())) { System.out.print(sp.getId() + ", "); } } System.out.println(); // System.out.println("Predictions: " + predictions); return predictions; }
From source file:ccm.pay2spawn.configurator.HTMLGenerator.java
public static void generate() throws IOException { ArrayList<Reward> sortedRewards = new ArrayList<>(); sortedRewards.addAll(Pay2Spawn.getRewardsDB().getRewards()); Collections.sort(sortedRewards, new Comparator<Reward>() { @Override// ww w.j a va 2 s.c o m public int compare(Reward o1, Reward o2) { return (int) (o1.getAmount() - o2.getAmount()); } }); File output = new File(htmlFolder, "index.html"); String text = readFile(templateIndex); int begin = text.indexOf(LOOP_START); int end = text.indexOf(LOOP_END); FileUtils.writeStringToFile(output, replace(text.substring(0, begin)), false); String loop = text.substring(begin + LOOP_START.length(), end); for (Reward reward : sortedRewards) { Pay2Spawn.getLogger().info("Adding " + reward + " to html file."); FileUtils.writeStringToFile(output, replace(loop, reward), true); } FileUtils.writeStringToFile(output, text.substring(end + LOOP_END.length(), text.length()), true); }
From source file:com.wavemaker.tools.pws.install.PwsInstall.java
public static void insertImport(File xmlFile, String resource) throws Exception { String content = getTrimmedXML(xmlFile); String fromStr1 = "<!DOCTYPE"; String toStr1 = "<!--!DOCTYPE"; content = content.replace(fromStr1, toStr1); String fromStr2 = "spring-beans-2.0.dtd\">"; String toStr2 = "spring-beans-2.0.dtd\"-->"; content = content.replace(fromStr2, toStr2); FileUtils.writeStringToFile(xmlFile, content, "UTF-8"); InputStream is = new FileInputStream(xmlFile); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);//from w w w . j a v a 2s . c o m DocumentBuilder docBuilder = dbf.newDocumentBuilder(); Document doc = docBuilder.parse(is); doc = insertImport(doc, resource); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); t.transform(new DOMSource(doc), new StreamResult(xmlFile)); content = FileUtils.readFileToString(xmlFile, "UTF-8"); content = content.replace(toStr1, fromStr1); content = content.replace(toStr2, fromStr2); FileUtils.writeStringToFile(xmlFile, content, "UTF-8"); }
From source file:com.thoughtworks.go.config.parts.PartialConfigHelper.java
public File writeFileWithContent(String relativePath, String content) throws Exception { File dest = new File(directory, relativePath); FileUtil.createParentFolderIfNotExist(dest); FileUtils.writeStringToFile(dest, content, UTF_8); return dest;/*from w w w .j av a 2 s . c o m*/ }
From source file:com.tunyk.mvn.plugins.htmlcompressor.FileTool.java
public void writeFiles(Map<String, String> map, String targetDir) throws IOException { for (String key : map.keySet()) { File file = new File(targetDir + "/" + key); FileUtils.writeStringToFile(file, map.get(key), fileEncoding); }/*from w ww. j a v a 2s . com*/ }
From source file:com.thoughtworks.go.util.ZipUtilTest.java
@BeforeEach void setUp() throws Exception { temporaryFolder.create();/* w ww. j a va 2 s.c o m*/ srcDir = temporaryFolder.newFolder("_test1"); destDir = temporaryFolder.newFolder("_test2"); emptyDir = new File(srcDir, "_emptyDir"); emptyDir.mkdir(); childDir1 = new File(srcDir, "_child1"); childDir1.mkdir(); file1 = new File(srcDir, "_file1"); FileUtils.writeStringToFile(file1, "_file1", UTF_8); file2 = new File(childDir1, "_file2"); FileUtils.writeStringToFile(file2, "_file2", UTF_8); zipUtil = new ZipUtil(); }
From source file:jsentvar.GenerateTestsResults.java
public void readerResult() throws IOException { RDFReader lector = new RDFReader(); String filename;/*from w ww . j a v a 2s . c om*/ filename = "resources/test/miniReasoner.owl"; Model model1; model1 = lector.reader(filename); System.out.println("readerResult():"); System.out.println(model1.toString()); FileUtils.writeStringToFile(new File("resources/test/mini_model.txt"), model1.toString(), "utf8"); }
From source file:cms.service.account.HTMLGenerator.java
public int save(String urlstr, String htmlName) { //System.out.println("?"+urlstr); String src = generate(urlstr); //System.out.println("html:"+src.toString()); File file = new File(this.getClass().getResource("/").getPath() + "../../html/" + htmlName); try {/*from w w w . j ava 2 s.c o m*/ FileUtils.writeStringToFile(file, src, "UTF-8"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //return Math.abs(src.hashCode());// return src.length();//?? }