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:gov.va.chir.tagline.dao.DatasetScoredSaver.java
public void saveRecords(final Collection<Document> documents) throws IOException { if (documents == null || documents.isEmpty()) { throw new IllegalArgumentException("There must be at least one document."); }// w w w . j ava 2s.co m // Write first line (if needed) if (!headerWritten) { saveHeader(); headerWritten = true; } final StringBuilder builder = new StringBuilder(); for (Document document : documents) { for (Line line : document.getLines()) { builder.append(document.getName()); builder.append("\t"); builder.append(line.getLineId()); builder.append("\t"); builder.append(line.getPredictedLabel()); builder.append("\t"); builder.append(line.getText()); builder.append(System.getProperty("line.separator")); } } FileUtils.writeStringToFile(file, builder.toString(), true); }
From source file:com.gemstone.gemfire.management.internal.cli.shell.GfshInitFileJUnitTest.java
@BeforeClass public static void setUpBeforeClass() throws Exception { saveLog4j2Config = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); saveUserDir = System.getProperty("user.dir"); saveUserHome = System.getProperty("user.home"); julLogger = java.util.logging.Logger.getLogger(""); saveHandlers = julLogger.getHandlers(); for (Handler handler : saveHandlers) { julLogger.removeHandler(handler); }/*w w w.j av a 2 s .c o m*/ File log4j2XML = temporaryFolder_Config.newFile("log4j2.xml"); FileUtils.writeStringToFile(log4j2XML, "<Configuration/>", APPEND); System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, log4j2XML.toURI().toString()); }
From source file:com.wavemaker.tools.project.upgrade.six_dot_zero.SpringXmlUpgradeTask.java
private void processSingleXml(File xmlf) { String fileName = xmlf.getName(); if (!fileName.contains("spring.xml")) { return;//from w w w.j a v a 2s.co m } try { String content = FileUtils.readFileToString(xmlf, ServerConstants.DEFAULT_ENCODING); content = content.replace(this.fromStr, this.toStr); FileUtils.writeStringToFile(xmlf, content, ServerConstants.DEFAULT_ENCODING); this.processed = true; } catch (IOException ioe) { ioe.printStackTrace(); this.error = true; } }
From source file:com.thoughtworks.go.config.GoConfigMigrationTest.java
@Test public void shouldCommitConfig_WithUsername_Upgrade() throws Exception { File file = temporaryFolder.newFile("my-config.xml"); FileUtils.writeStringToFile(file, OLDER_VERSION_XML, UTF_8); final GoConfigRevision[] commitMade = new GoConfigRevision[1]; doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) throws Throwable { commitMade[0] = (GoConfigRevision) invocation.getArguments()[0]; return null; }/*from w w w .ja v a 2 s.c o m*/ }).when(configRepo).checkin(any(GoConfigRevision.class)); goConfigMigration.upgradeIfNecessary(file, null); assertThat(commitMade[0].getUsername(), is(GoConfigMigration.UPGRADE)); }
From source file:com.github.stagirs.docextractor.latex.LatexDocProcessorTest.java
@Test public void test() throws IOException { DocIterator docs = new DocIterator(new File("W:\\apache-tomcat-8.0.37\\work\\stagirs\\docs\\collection")); while (docs.hasNext()) { Text text = docs.next();// ww w .ja va 2s. c o m try { FileUtils.writeStringToFile( new File("W:\\apache-tomcat-8.0.37\\work\\stagirs\\docs\\processed\\" + text.id), new ObjectMapper().writeValueAsString(new LatexDocProcessor().processDocument(text.id, text.text.replace("\\end", "\\end"))), "utf-8"); } catch (Throwable e) { System.err.println(text.id); e.printStackTrace(); } } }
From source file:de.fraunhofer.iosb.ilt.stc.FXMLController.java
@FXML private void actionSave(ActionEvent event) { JsonElement json = configEditor.getConfig(); String config = new GsonBuilder().setPrettyPrinting().create().toJson(json); fileChooser.setTitle("Save Config"); File file = fileChooser.showSaveDialog(paneConfig.getScene().getWindow()); try {/* w w w . j a v a 2s .c o m*/ FileUtils.writeStringToFile(file, config, "UTF-8"); } catch (IOException ex) { LOGGER.error("Failed to write file.", ex); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("failed to write file"); alert.setContentText(ex.getLocalizedMessage()); alert.showAndWait(); } }
From source file:de.pawlidi.openaletheia.generator.KeyGenerator.java
/** * Creates key file for given root directory, generated key and file name. * //from w ww . ja va 2 s. c om * @param rootDir * - root directory to store in the key file * @param key * - generated key * @param fileName * - file name to store the key */ public static boolean createKeyFile(File rootDir, String key, String fileName) { try { FileUtils.writeStringToFile(new File(rootDir, fileName), key, Converter.UTF_8); return true; } catch (IOException e) { return false; } }
From source file:edu.cuhk.hccl.YelpApp.java
@Override public void run(String[] args) throws IOException { super.run(args); // Put into itemSet once all business_ids for some category (e.g. restaurant) from a file String businessFile = cmdLine.getOptionValue('b'); String category = cmdLine.getOptionValue('c'); if (itemSet.isEmpty()) { try {//from w ww.j ava 2 s. c o m List<String> lines = FileUtils.readLines(new File(businessFile), "UTF-8"); for (String line : lines) { Business business = gson.fromJson(line, Business.class); boolean isIn = false; for (String cate : business.categories) { if (category.equals(cate.toLowerCase())) { isIn = true; break; } } if (isIn) { if (!itemSet.contains(business.business_id)) { itemSet.add(business.business_id); } } } } catch (IOException e) { e.printStackTrace(); } } // Process data file and save result String dataFileName = cmdLine.getOptionValue('f'); String result = processStream(dataFileName).toString(); FileUtils.writeStringToFile(outFile, result, false); System.out.println("Processing is fininshed!"); }
From source file:gov.va.chir.tagline.dao.AnnotationsSaver.java
public void saveRecords(final Collection<Document> documents) throws IOException { if (documents == null || documents.isEmpty()) { throw new IllegalArgumentException("There must be at least one document."); }//from www . j ava 2s . co m // Write first line (if needed) if (!headerWritten) { saveHeader(); headerWritten = true; } final StringBuilder builder = new StringBuilder(); for (Document document : documents) { for (Annotation annotation : document.getAnnotations()) { builder.append(document.getName()); builder.append("\t"); builder.append(annotation.getStart()); builder.append("\t"); builder.append(annotation.getEnd()); builder.append("\t"); builder.append(annotation.getType()); builder.append(System.getProperty("line.separator")); } } FileUtils.writeStringToFile(file, builder.toString(), true); }
From source file:com.thoughtworks.go.agent.AgentPluginsInitializerIntegrationTest.java
@Test void shouldRemoveExistingBundledPluginsBeforeInitializingNewPlugins() throws Exception { File existingBundledPlugin = new File(directoryForUnzippedPlugins, "bundled/existing-plugin-1.jar"); setupAgentsPluginFile().withBundledPlugin("new-plugin-1.jar", "SOME-PLUGIN-CONTENT").done(); FileUtils.writeStringToFile(existingBundledPlugin, "OLD-CONTENT", UTF_8); agentPluginsInitializer.onApplicationEvent(null); assertThat(existingBundledPlugin.exists()).isFalse(); assertThat(new File(directoryForUnzippedPlugins, "bundled/new-plugin-1.jar").exists()).isTrue(); }