List of usage examples for org.apache.commons.io FileUtils writeLines
public static void writeLines(File file, Collection lines, String lineEnding) throws IOException
toString()
value of each item in a collection to the specified File
line by line. From source file:org.apache.oodt.cas.pge.TestPGETaskInstance.java
@Test public void testCreatePgeConfig() throws Exception { final String KEY = "TestKey"; final String VALUE = "TestValue"; File pgeConfigFile = new File(createTmpDir(), "pgeConfig.xml"); FileUtils.writeLines(pgeConfigFile, "UTF-8", Lists.newArrayList("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<pgeConfig>", " <customMetadata>", " <metadata key=\"" + KEY + "\" val=\"" + VALUE + "\"/>", " </customMetadata>", "</pgeConfig>")); PGETaskInstance pgeTask = createTestInstance(); pgeTask.pgeMetadata.replaceMetadata(CONFIG_FILE_PATH, pgeConfigFile.getAbsolutePath()); PgeConfig pgeConfig = pgeTask.createPgeConfig(); assertNotNull(pgeConfig);/*w w w . j a v a 2 s . c o m*/ assertEquals(VALUE, pgeTask.pgeMetadata.getMetadata(KEY)); pgeTask = createTestInstance(); pgeTask.pgeMetadata.replaceMetadata(PGE_CONFIG_BUILDER, MockPgeConfigBuilder.class.getCanonicalName()); pgeConfig = pgeTask.createPgeConfig(); assertEquals(MockPgeConfigBuilder.MOCK_EXE_DIR, pgeConfig.getExeDir()); }
From source file:org.blocks4j.commons.metrics3.MetricCounterBackup.java
public void persist(String name, long value) { String normalized = normalize(name); try {/*from w ww . j a v a2s .co m*/ File output = new File(base, normalized); FileUtils.writeLines(output, Arrays.asList(String.valueOf(value)), false); } catch (Exception e) { log.error("error while writing to file [" + base.getName() + System.getProperty("file.separator") + normalized + "]", e); } }
From source file:org.camunda.bpm.benchmark.report.CsvReportWriter.java
public void write(MetricsResults result) { File file = new File(fileName); List<String> lines = new ArrayList<String>(); // header//from w w w. ja va 2s .c om addLine(lines, "reporter", "metric", "reporter_metric", "operator", "intervalStart", "intervalEnd", "value"); for (Map.Entry<String, List<MetricsResultInstance>> resultsByReporter : result.getMetricsByReporter() .entrySet()) { for (MetricsResultInstance resultInstance : resultsByReporter.getValue()) { addLine(lines, resultsByReporter.getKey(), resultInstance.getMetricName(), resultsByReporter.getKey() + "_" + resultInstance.getMetricName(), resultInstance.getOperator(), formatDate(resultInstance.getStartDate()), formatDate(resultInstance.getEndDate()), resultInstance.getValue()); } } for (MetricsResultInstance resultInstance : result.getAggregatedResults()) { addLine(lines, "aggregated", resultInstance.getMetricName(), "aggregated_" + resultInstance.getMetricName(), resultInstance.getOperator(), formatDate(resultInstance.getStartDate()), formatDate(resultInstance.getEndDate()), resultInstance.getValue()); } System.out.println("Writing to " + file.getAbsolutePath()); try { FileUtils.writeLines(file, "UTF-8", lines); } catch (IOException e) { throw new RuntimeException("Could not write to file " + fileName, e); } }
From source file:org.codehaus.mojo.exec.test1.Test.java
public static void main(String[] args) throws Exception { // make sure junit classes are in the classpath Assert.assertTrue("missing output file path", args.length > 0); List myProperties = new ArrayList(); for (int i = 0; i < args.length - 1; i++) { myProperties.add("arg." + args[i + 1]); }/*from w w w . ja v a 2 s . c o m*/ Properties systemProperties = System.getProperties(); for (Iterator it = systemProperties.keySet().iterator(); it.hasNext();) { String key = it.next().toString(); if (key.startsWith("project.")) { myProperties.add(key + "=" + systemProperties.get(key)); } } Collections.sort(myProperties); File toFile = new File(args[0]); System.out.println(toFile.getAbsolutePath()); toFile.getParentFile().mkdirs(); FileUtils.writeLines(new File(args[0]), "UTF-8", myProperties); }
From source file:org.codehaus.mojo.exec.test3.Test.java
public static void main(String[] args) throws Exception { if (args.length == 0) { throw new IllegalArgumentException("missing output file path"); }/* w w w .j a v a2 s .c o m*/ List myProperties = new ArrayList(); for (int i = 0; i < args.length - 1; i++) { myProperties.add("arg." + args[i + 1]); } Properties systemProperties = System.getProperties(); for (Iterator it = systemProperties.keySet().iterator(); it.hasNext();) { String key = it.next().toString(); if (key.startsWith("project.")) { myProperties.add(key + "=" + systemProperties.get(key)); } } myProperties.add("user.dir=" + systemProperties.get("user.dir")); myProperties.add("java.class.path=" + systemProperties.get("java.class.path")); Collections.sort(myProperties); File toFile = new File(args[0]); toFile.getParentFile().mkdirs(); FileUtils.writeLines(new File(args[0]), "UTF-8", myProperties); }
From source file:org.commonjava.aprox.subsys.datafile.DataFile.java
public void writeLines(final List<String> lines, final String encoding, final ChangeSummary summary) throws IOException { FileUtils.writeLines(file, lines, encoding); events.modified(file, summary);//from ww w .j a va 2s.c om }
From source file:org.commonjava.aprox.subsys.datafile.DataFile.java
public void appendLines(final List<String> lines, final ChangeSummary summary) throws IOException { FileUtils.writeLines(file, lines, true); events.modified(file, summary);//from w w w . j a va2 s. c om }
From source file:org.eclipse.smarthome.core.service.AbstractWatchServiceTest.java
private void assertByRelativePath(String fileName) throws Exception { File file = new File(WATCHED_DIRECTORY + File.separatorChar + fileName); file.getParentFile().mkdirs();//from w w w .j av a2 s.c om assertThat(file.exists(), is(false)); // We have to be sure that all the subdirectories of the watched directory are created when the watched service // is activated watchService.activate(); file.createNewFile(); fullEventAssertionsByKind(fileName, ENTRY_CREATE, false); // File modified FileUtils.writeLines(file, Collections.singletonList("Additional content"), true); fullEventAssertionsByKind(fileName, ENTRY_MODIFY, false); // File modified but identical content FileUtils.writeLines(file, Collections.singletonList("Additional content"), false); assertNoEventsAreProcessed(); // File deleted file.delete(); fullEventAssertionsByKind(fileName, ENTRY_DELETE, true); }
From source file:org.haedus.io.DiskFileHandler.java
@Override public void writeLines(String path, List<String> data) { File file = new File(path); try {//from w w w .jav a2 s. c o m FileUtils.writeLines(file, encoding, data); } catch (IOException e) { LOGGER.error("Error when writing to \"{}\"!", path, e); } }
From source file:org.ikasan.component.endpoint.filesystem.producer.FileProducer.java
/** * Write the payload to the file based on the incoming payload type. * @param file/*from w w w . j a va 2s .c o m*/ * @param payload * @throws IOException */ protected void writeFile(File file, Object payload) throws IOException { if (payload instanceof String) { FileUtils.writeStringToFile(file, (String) payload, configuration.getEncoding()); } else if (payload instanceof byte[]) { FileUtils.writeByteArrayToFile(file, (byte[]) payload); } if (payload instanceof Collection) { if (configuration.getLineEnding() != null) { FileUtils.writeLines(file, (Collection) payload, configuration.getLineEnding()); } else { FileUtils.writeLines(file, (Collection) payload); } } }