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:com.thesmartweb.swebrank.DataManipulation.java
/** * Method that writes a List to a file//w ww.ja va2s .co m * @param wordList List to be saved * @param file_wordlist The file in a string format that the List is going to be saved * @return True/False */ public boolean AppendWordList(List<String> wordList, String file_wordlist) { //----------------append the wordlist to a file File wordlist_file = new File(file_wordlist); try { FileUtils.writeLines(wordlist_file, wordList); return true; } catch (IOException ex) { Logger.getLogger(DataManipulation.class.getName()).log(Level.SEVERE, null, ex); return false; } }
From source file:gov.nih.nci.caarray.magetab.splitter.SdrfSplitter.java
/** * Creates a small sdrf file which contains only rows that have not been split out by calls to * {@link #splitByDataFile(FileRef)}./*from w w w . j a v a 2 s . c o m*/ * Returns null if there are no unused rows. * * @return small sdrf consisting of unused rows * @throws IOException if writing to new files fails or any other io error */ public FileRef splitByUnusedLines() throws IOException { if (unusedLines.size() == HEADER_ONLY) { return null; } File outputFile = File.createTempFile(file.getName(), ".sdrf"); FileUtils.writeLines(outputFile, unusedLines); return new JavaIOFileRef(outputFile); }
From source file:com.github.jrh3k5.plugin.maven.l10n.data.AbstractMessagesPropertiesParserTest.java
/** * The search for duplicate translation keys should skip comments. * //w ww.j av a 2 s .c om * @throws Exception * If any errors occur during the test run. */ @Test public void testGetDuplicateTranslationKeysWithComment() throws Exception { final File testFile = getTestFile("messages.properties"); FileUtils.writeLines(testFile, Arrays.asList("comment.dup=foo", "comment.not.dup=bar", "# This is a comment", "comment.dup=fizzbuzz")); assertThat(parser.getDuplicateTranslationKeys(testFile)).hasSize(1).contains("comment.dup"); }
From source file:com.splicemachine.derby.impl.sql.actions.index.CsvUtil.java
public static void writeLines(String dirName, String fileName, Collection<String> content) throws Exception { File targetFile = new File(dirName, fileName); Files.createParentDirs(targetFile); if (targetFile.exists()) targetFile.delete();// w w w . j a v a2 s .c o m targetFile.createNewFile(); FileUtils.writeLines(targetFile, content); }
From source file:com.gargoylesoftware.htmlunit.runners.TestCaseCorrector.java
static void correct(final FrameworkMethod method, final boolean realBrowser, final BrowserVersion browserVersion, final boolean notYetImplemented, final Throwable t) throws IOException { final String testRoot = "src/test/java/"; final String browserString = browserVersion.getNickname().toUpperCase(Locale.ROOT); final File file = new File(testRoot + method.getDeclaringClass().getName().replace('.', '/') + ".java"); final List<String> lines = FileUtils.readLines(file); final String methodLine = " public void " + method.getName() + "()"; if (realBrowser) { String defaultExpectation = null; for (int i = 0; i < lines.size(); i++) { if (" @Default".equals(lines.get(i))) { defaultExpectation = getDefaultExpectation(lines, i); }//from w w w . j a v a 2 s. c om if (lines.get(i).startsWith(methodLine)) { i = addExpectation(lines, i, browserString, (ComparisonFailure) t); break; } if (i == lines.size() - 2) { addMethodWithExpectation(lines, i, browserString, method.getName(), (ComparisonFailure) t, defaultExpectation); break; } } } else if (!notYetImplemented) { String defaultExpectation = null; for (int i = 0; i < lines.size(); i++) { if (" @Default".equals(lines.get(i))) { defaultExpectation = getDefaultExpectation(lines, i); } if (lines.get(i).startsWith(methodLine)) { addNotYetImplemented(lines, i, browserString); break; } if (i == lines.size() - 2) { addNotYetImplementedMethod(lines, i, browserString, method.getName(), defaultExpectation); break; } } } else { for (int i = 0; i < lines.size(); i++) { if (lines.get(i).startsWith(methodLine)) { removeNotYetImplemented(lines, i, browserString); break; } } } FileUtils.writeLines(file, lines); }
From source file:com.thesmartweb.swebrank.Diffbot.java
/** * Method to get the words recognized by Diffbot as important in given urls * @param links the urls to analyzes//from w ww. j ava 2s.c o m * @param directory the directory to save the output * @param config_path the configuration path to get the diffbot key * @return a list of the words */ public List<String> compute(String[] links, String directory, String config_path) { List<String> wordList = null; try { URL diff_url = null; String stringtosplit = ""; String token = GetToken(config_path); for (String link : links) { if (!(link == null)) { diff_url = new URL( "http://api.diffbot.com/v2/article?token=" + token + "&fields=tags,meta&url=" + link); APIconn apiconn = new APIconn(); String line = apiconn.connect(diff_url); JSONparsing jp = new JSONparsing(); stringtosplit = jp.DiffbotParsing(line); if (!(stringtosplit == null) && (!(stringtosplit.equalsIgnoreCase("")))) { stringtosplit = stringtosplit.replaceAll("[\\W&&[^\\s]]", ""); if (!(stringtosplit == null) && (!(stringtosplit.equalsIgnoreCase("")))) { String[] tokenizedTerms = stringtosplit.split("\\W+"); //to get individual terms for (String tokenizedTerm : tokenizedTerms) { if (!(tokenizedTerm == null) && (!(tokenizedTerm.equalsIgnoreCase("")))) { wordList.add(tokenizedTerm); } } } } } } File file_words = new File(directory + "words.txt"); FileUtils.writeLines(file_words, wordList); return wordList; } catch (MalformedURLException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); return wordList; } catch (IOException ex) { Logger.getLogger(Diffbot.class.getName()).log(Level.SEVERE, null, ex); return wordList; } }
From source file:com.l2jfree.tools.ProjectSettingsSynchronizer.java
private static void writeLines(File parentFile, String fileName, Collection<String> lines) throws IOException { final File destinationFile = new File(parentFile, fileName); System.out.println("Copying: " + destinationFile); FileUtils.writeLines(destinationFile, lines); }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.KeyphraseGoldStandardFilter.java
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { DocumentMetaData md = DocumentMetaData.get(jcas); String goldFile = md.getDocumentUri().substring(0, md.getDocumentUri().lastIndexOf(".")).replace("file:", "") + goldSuffix; System.out.println("Loading gold standard from " + goldFile); try {/*from w ww. jav a2 s . c o m*/ List<String> keyphrases = FileUtils.readLines(new File(goldFile)); List<String> filteredKeyphrases = new ArrayList<String>(); List<String> lemmas = new ArrayList<String>(); for (Lemma lemma : JCasUtil.select(jcas, Lemma.class)) { lemmas.add(lemma.getValue().toLowerCase()); } List<String> tokens = new ArrayList<String>(); for (Token token : JCasUtil.select(jcas, Token.class)) { tokens.add(token.getCoveredText().toLowerCase()); } for (String keyphrase : keyphrases) { if (tokens.contains(keyphrase.toLowerCase()) || lemmas.contains(keyphrase.toLowerCase())) { filteredKeyphrases.add(keyphrase); } } FileUtils.writeLines(new File(goldFile + ".filtered"), filteredKeyphrases); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } }
From source file:ca.weblite.xmlvm.ConstantPoolHelper.java
public static void removeConstantPoolDependencies(Map<Integer, Constant> constantPool, File file) throws IOException { String strPattern = "xmlvm_create_java_string_from_pool\\((\\d+)\\)"; Pattern regex = Pattern.compile(strPattern); List<String> lines = FileUtils.readLines(file); List<String> out = new ArrayList<String>(); boolean changed = false; for (String line : lines) { if (line.indexOf("xmlvm_create_java_string_from_pool") != -1) { Matcher m = regex.matcher(line); if (m.find()) { String idStr = m.group(1); Constant theConstant = constantPool.get(Integer.parseInt(idStr)); String strVal = theConstant.data; int len = theConstant.len; if (strVal == null) { throw new RuntimeException("Constant pool does not contain string id " + idStr); }/*w w w.j a v a 2s . com*/ changed = true; line = line.replaceAll(strPattern, "xmlvm_create_java_string_from_char_array((JAVA_OBJECT)" + strVal + "," + len + ")"); } } out.add(line); } if (changed) { FileUtils.writeLines(file, out); } }
From source file:com.sillelien.dollar.DollarOperatorsRegressionTest.java
public void regression(String symbol, String operation, String variant, @NotNull List<List<var>> result) throws IOException { String filename = operation + "." + variant + ".json"; final JsonArray previous = new JsonArray(IOUtils.toString(getClass().getResourceAsStream("/" + filename))); //Use small to stop massive string creation final File file = new File("target", filename); final var current = $(result); FileUtils.writeStringToFile(file, current.jsonArray().encodePrettily()); System.out.println(file.getAbsolutePath()); SortedSet<String> typeComparison = new TreeSet<>(); SortedSet<String> humanReadable = new TreeSet<>(); for (List<var> res : result) { if (res.size() != 3) { throw new IllegalStateException(res.toString()); }//w ww.j a v a 2 s. c o m typeComparison.add( res.get(0).$type() + " " + operation + " " + res.get(1).$type() + " = " + res.get(2).$type()); humanReadable.add(res.get(0).toDollarScript() + " " + symbol + " " + res.get(1).toDollarScript() + " <=> " + res.get(2).toDollarScript()); } final String typesFile = operation + "." + variant + ".types.txt"; final String humanFile = operation + "." + variant + ".ds"; FileUtils.writeLines(new File("target", typesFile), typeComparison); FileUtils.writeLines(new File("target", humanFile), humanReadable); final TreeSet previousTypeComparison = new TreeSet<String>( IOUtils.readLines(getClass().getResourceAsStream("/" + typesFile))); diff("type", previousTypeComparison.toString(), typeComparison.toString()); diff("result", previous, current.jsonArray()); }