List of usage examples for org.apache.commons.io FileUtils writeLines
public static void writeLines(File file, Collection lines) throws IOException
toString()
value of each item in a collection to the specified File
line by line. From source file:eu.europeana.datamigration.ese2edm.LogCleaner.java
public static void main(String[] args) { try {//from w w w .j a v a 2 s. co m List<String> lines = FileUtils.readLines(new File("/home/gmamakis/test.log")); List<String> newLines = new ArrayList<String>(); for (String line : lines) { if (!line.startsWith("Apr")) { newLines.add(line); } } FileUtils.writeLines(new File("/home/gmamakis/rdfslabel.log"), newLines); } catch (IOException ex) { Logger.getLogger(LogCleaner.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.unisb.cs.st.javalanche.mutation.util.CsvWriter.java
public static void main(String[] args) throws IOException { // Set<Long> covered = MutationCoverageFile.getCoveredMutations(); // List<Long> mutationIds = QueryManager.getMutationsWithoutResult( // covered, 0); Session session = HibernateUtil.getSessionFactory().openSession(); List<Mutation> mutations = QueryManager.getMutationsForProject( ConfigurationLocator.getJavalancheConfiguration().getProjectPrefix(), session); logger.info("Got " + mutations.size() + " mutation ids."); List<String> lines = new ArrayList<String>(); lines.add(Mutation.getCsvHead() + ",DETECTED"); int counter = 0; int flushs = 0; StopWatch stp = new StopWatch(); for (Mutation mutation : mutations) { // Mutation mutation = QueryManager.getMutationByID(id, session); lines.add(mutation.getCsvString() + "," + mutation.isKilled()); counter++;/*from w ww. jav a2s .c o m*/ if (counter > 20) { counter = 0; // 20, same as the JDBC batch size // flush a batch of inserts and release memory: // see // http://www.hibernate.org/hib_docs/reference/en/html/batch.html stp.reset(); stp.start(); flushs++; session.flush(); // session.clear(); logger.info("Did flush. It took: " + DurationFormatUtils.formatDurationHMS(stp.getTime())); } } session.close(); logger.info("Starting to write file with " + lines.size() + " entries."); FileUtils.writeLines(new File("mutations.csv"), lines); }
From source file:com.incapture.rapgen.output.OutputWriter.java
public static void writeList(String outputKernelFolder, List<String> list, String filePath) { String filepath = outputKernelFolder + "/" + AbstractTTree.GEN_PATH_PREFIX + filePath; File file = new File(filepath); try {/*from w w w.j ava2s . c o m*/ FileUtils.writeLines(file, list); } catch (IOException e) { System.err.println(ExceptionToString.format(e)); } }
From source file:net.landora.video.filestate.DirectoryUUIDChecker.java
public static void setUUID(File directory, String uuid) { try {//from w w w. j a v a 2 s. com File uuidFile = new File(directory, UUID_FILE); Set<String> uuids = new LinkedHashSet<String>(); if (uuidFile.exists()) { uuids.addAll(FileUtils.readLines(uuidFile)); } uuids.add(uuid); FileUtils.writeLines(uuidFile, uuids); } catch (Exception e) { log.error("Error adding directory uuid: " + directory, e); } }
From source file:ch.unibas.fittingwizard.application.xyz.ZxyGenerator.java
public File generateFrom(File coordinateFile) { File zxyFile = prepareFile(coordinateFile); readLinesFromFile(coordinateFile);//w w w . ja v a 2s .c o m if (content.size() <= HeaderLine) { throw new RuntimeException("Only header found in coordinate file " + coordinateFile); } try { FileUtils.writeLines(zxyFile, content.subList(FirstAtomLine, content.size())); } catch (IOException e) { throw new RuntimeException("Could not write to zxy file."); } return zxyFile; }
From source file:edu.isi.pfindr.learn.util.PairsFileIO.java
@SuppressWarnings("unchecked") public static void shuffler(String pairsFilename) throws IOException { List<String> fileWithPairs = FileUtils.readLines(new File(pairsFilename)); Collections.shuffle(fileWithPairs); String outputFilename = pairsFilename.split("\\.")[0] + "_s.txt"; //output filename derived from the pairs filename FileUtils.writeLines(new File(outputFilename), fileWithPairs); }
From source file:com.gs.obevo.util.FileUtilsCobra.java
public static void writeLines(File file, Collection<?> lines) { try {/*from w w w.j a va 2 s.co m*/ FileUtils.writeLines(file, lines); } catch (IOException e) { throw new IllegalArgumentException(e); } }
From source file:fi.otavanopisto.changelogger.Changelogger.java
private static void prependLine(String line, String message) throws IOException, GitAPIException { FileRepositoryBuilder frBuilder = new FileRepositoryBuilder(); Repository repository = frBuilder.setGitDir(new File("./.git")).readEnvironment().build(); Git git = new Git(repository); git.reset().setMode(ResetCommand.ResetType.HARD).call(); git.clean().call();// w ww . j a v a 2s . c om git.fetch().call(); git.pull().call(); File file = new File(CHANGELOG_FILE); List<String> lines = FileUtils.readLines(file, Charsets.UTF_8); lines.add(0, line); FileUtils.writeLines(file, lines); git.commit().setMessage(message).setAuthor("Changelogger", "changelogger@otavanopisto.fi").call(); git.push().call(); }
From source file:ch.unibas.fittingwizard.application.tools.charges.ChargesFileGenerator.java
public File generate(File destination, String chargesFileName, LinkedHashSet<ChargeValue> chargeValues) { destination.mkdir();/*w w w . j a v a 2s . c o m*/ if (destination == null || !destination.isDirectory()) { throw new IllegalArgumentException("Invalid destination directory."); } if (chargeValues == null || chargeValues.size() == 0) { throw new IllegalArgumentException("chargeValues are empty."); } File output = new File(destination, chargesFileName); output.delete(); List<String> content = new ArrayList<>(); for (ChargeValue chargeLine : chargeValues) { String line = String.format("%s_%s %s", chargeLine.getAtomTypeId().getName(), chargeLine.getType(), String.valueOf(chargeLine.getValue())); content.add(line); } try { FileUtils.writeLines(output, content); } catch (IOException e) { throw new RuntimeException("Could not write charges file."); } return output; }
From source file:com.aliyun.odps.graph.local.message.MsgBuffer.java
public void dump(File out) throws IOException { synchronized (msges) { FileUtils.writeLines(out, msges); } }