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:edu.cmu.cs.lti.discoursedb.annotation.brat.io.BratService.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = true) public void exportDiscoursePart(DiscoursePart dp, String outputFolder, Boolean threaded) throws IOException { Assert.notNull(dp, "The DiscoursePart cannot be null"); Assert.hasText(outputFolder, "The outputFolder has to be specified"); //define a common base filename for all files associated with this DiscoursePart String baseFileName = discoursePart2BratName(dp); //dp.getClass().getAnnotation(Table.class).name() + "_"+dp.getId(); // delete me//w ww. j a va2s . c o m //The offset mapping keeps track of the start positions of each contribution/content in the aggregated txt file List<OffsetInfo> entityOffsetMapping = new ArrayList<>(); List<String> discoursePartText = new ArrayList<>(); List<BratAnnotation> bratAnnotations = new ArrayList<>(); BratIdGenerator bratIdGenerator = new BratIdGenerator(); int spanOffset = 0; // Sort contributions by their start time, without crashing on null List<Contribution> contribsTimeOrdered = Lists.newArrayList(contribService.findAllByDiscoursePart(dp)); //This should be (maybe, optionally) a depth-first sort, with start time as a tiebreaker. contribsTimeOrdered.sort((c1, c2) -> { if (c1 == null) { return -1; } else if (c2 == null) { return 1; } else if (c1.getStartTime() == c2.getStartTime()) { return c1.getId().compareTo(c2.getId()); } else { return c1.getStartTime().compareTo(c2.getStartTime()); } }); List<Contribution> contribs = null; if (threaded) { contribs = utilService.threadsort(contribsTimeOrdered, c -> c.getId(), c -> { Contribution p = contribService.getOneRelatedContribution(c); if (p == null) { return 0L; } else { return p.getId(); } }); } else { contribs = contribsTimeOrdered; } // Export current revision of sorted contributions for (Contribution contrib : contribs) { Content curRevision = contrib.getCurrentRevision(); String text = curRevision.getText(); String sep = new BratSeparator(0, contrib.getCurrentRevision().getAuthor().getUsername(), contrib.getCurrentRevision().getTitle(), contrib.getStartTime()).get(); discoursePartText.add(sep); discoursePartText.add(text); //annotations on content for (AnnotationInstance anno : annoService.findAnnotations(curRevision)) { bratAnnotations .addAll(convertAnnotationToBrat(anno, spanOffset, sep, text, curRevision, bratIdGenerator)); } //annotations on contributions for (AnnotationInstance anno : annoService.findAnnotations(contrib)) { bratAnnotations .addAll(convertAnnotationToBrat(anno, spanOffset, sep, text, contrib, bratIdGenerator)); } //keep track of offsets entityOffsetMapping.add(new OffsetInfo(spanOffset, contrib.getId(), curRevision.getId())); //update span offsets spanOffset += text.length() + 1; spanOffset += BratSeparator.length + 1; } if (contribs.size() > 0) { FileUtils.writeLines(new File(outputFolder, baseFileName + ".txt"), discoursePartText); FileUtils.writeLines(new File(outputFolder, baseFileName + ".ann"), bratAnnotations); FileUtils.writeLines(new File(outputFolder, baseFileName + ".offsets"), entityOffsetMapping); FileUtils.writeLines(new File(outputFolder, baseFileName + ".versions"), bratAnnotations.stream() .map(anno -> anno.getVersionInfo()).filter(Objects::nonNull).collect(Collectors.toList())); } }
From source file:com.taobao.android.builder.tools.proguard.BundleProguarder.java
private static File printInOut(AppVariantContext appVariantContext, Input input) throws IOException { File proguardDir = input.proguardOutputDir; if (null == proguardDir) { proguardDir = appVariantContext.getAwbProguardDir(input.getAwbBundles().get(0).getAwbBundle()); }//from w w w .j ava 2s. c o m proguardDir.mkdirs(); File inoutConfigs = new File(proguardDir, INOUT_CFG); List<String> configs = new ArrayList<>(); for (AwbTransform awbTransform : input.getAwbBundles()) { List<File> inputLibraries = Lists.newArrayList(); for (File inputLibrary : awbTransform.getInputLibraries()) { configs.add(INJARS_OPTION + " " + inputLibrary.getAbsolutePath()); String name = FileNameUtils.getUniqueJarName(inputLibrary); File obsJar = new File(proguardDir, name + ".jar"); input.proguardJarMap.put(obsJar, input.getFileMd5s().get(inputLibrary)); inputLibraries.add(obsJar); configs.add(OUTJARS_OPTION + " " + obsJar.getAbsolutePath()); if (inputLibrary.isDirectory() && AtlasBuildContext.atlasMainDexHelperMap .get(appVariantContext.getVariantName()).getInputDirs().contains(inputLibrary)) { input.maindexFolderTransform.put(inputLibrary, obsJar); } else if (AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()) .inMainDex(inputLibrary)) { input.maindexFileTransform.put(inputLibrary, obsJar); // AtlasBuildContext.atlasMainDexHelper.updateMainDexFile(inputLibrary, obsJar); } else if (awbTransform.getAwbBundle().isMainBundle()) { AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()) .addMainDex(new BuildAtlasEnvTask.FileIdentity(obsJar.getName(), obsJar, false, false)); } } //configs.add(); if (null != awbTransform.getInputDir() && awbTransform.getInputDir().exists()) { configs.add(INJARS_OPTION + " " + awbTransform.getInputDir().getAbsolutePath()); String name = input.getFileMd5s().get(awbTransform.getInputDir()); if (null == name) { name = FileNameUtils.getUniqueFileName(awbTransform.getInputDir().getName(), "proguard"); } File obsJar = new File(proguardDir, name + ".jar"); inputLibraries.add(obsJar); configs.add(OUTJARS_OPTION + " " + obsJar.getAbsolutePath()); if (awbTransform.getAwbBundle().isMainBundle()) { AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getInputDirs() .clear(); AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()) .addMainDex(new BuildAtlasEnvTask.FileIdentity(obsJar.getName(), obsJar, false, false)); } } awbTransform.setInputFiles(inputLibraries); awbTransform.setInputDir(null); awbTransform.getInputLibraries().clear(); } for (File library : input.getLibraries()) { configs.add("-libraryjars " + library.getAbsolutePath()); } FileUtils.writeLines(inoutConfigs, configs); return inoutConfigs; }
From source file:com.taobao.android.PatchFieldTool.java
/** * ?dexfield,???String//from ww w . j a v a 2s. co m * * @param dexFile * @param outDexFile * @param orgFieldValue * @param newFieldValue * @return */ public static boolean modifyFieldValue(File dexFile, File outDexFile, String orgFieldValue, String newFieldValue) throws IOException, RecognitionException { File smaliFolder = new File(outDexFile.getParentFile(), "smali"); if (smaliFolder.exists()) { FileUtils.deleteDirectory(smaliFolder); } smaliFolder.mkdirs(); boolean disassembled = SmaliUtils.disassembleDexFile(dexFile, smaliFolder); if (disassembled) { Collection<File> smaliFiles = FileUtils.listFiles(smaliFolder, new String[] { "smali" }, true); for (File smaliFile : smaliFiles) { List<String> lines = FileUtils.readLines(smaliFile); for (int index = 0; index < lines.size(); index++) { String line = lines.get(index); String newLine = StringUtils.replace(line, "\"" + orgFieldValue + "\"", "\"" + newFieldValue + "\""); lines.set(index, newLine); } FileUtils.writeLines(smaliFile, lines); } //?dex boolean assembled = SmaliUtils.assembleSmaliFile(smaliFolder, outDexFile); if (assembled) { FileUtils.deleteDirectory(smaliFolder); return true; } } return false; }
From source file:com.yenlo.synapse.transport.vfs.VFSTransportListener.java
private synchronized void addFailedRecord(PollTableEntry pollTableEntry, FileObject failedObject, String timeString) {//from w w w. ja va 2 s .c o m try { String record = failedObject.getName().getBaseName() + VFSConstants.FAILED_RECORD_DELIMITER + timeString; String recordFile = pollTableEntry.getFailedRecordFileDestination() + pollTableEntry.getFailedRecordFileName(); File failedRecordFile = new File(recordFile); if (!failedRecordFile.exists()) { FileUtils.writeStringToFile(failedRecordFile, record); if (log.isDebugEnabled()) { log.debug("Added fail record '" + record + "' into the record file '" + recordFile + "'"); } } else { List<String> content = FileUtils.readLines(failedRecordFile); if (!content.contains(record)) { content.add(record); } FileUtils.writeLines(failedRecordFile, content); } } catch (IOException e) { log.fatal("Failure while writing the failed records!", e); } }
From source file:com.thesmartweb.swebrank.WebParser.java
/** * Method to get all the elements with a specific html feature (not used in SWebRank's current version) * @param link_html the url to check// w ww. j ava 2 s. c o m * @param dir the directory to save the file * @return a list with the text of all the elements */ public List<String> getbold(String link_html, String dir) { List<String> SEwords = new ArrayList<String>(); try { //link_html="http://www.themismavridis.com/"; Document doc = Jsoup.connect(link_html).get(); //---------to select the rest of the terms Elements bold = doc.select("em"); //bold=bold.select("b"); for (Element btext : bold) { String stringtosplit = btext.text().toString().toString(); if (!(stringtosplit == null) && (!(stringtosplit.equalsIgnoreCase("")))) { stringtosplit = stringtosplit.replaceAll("[\\W&&[^\\s]]", ""); if (!(stringtosplit == null) && (!(stringtosplit.equalsIgnoreCase("")))) { String[] tokenizedTerms = stringtosplit.split("\\W+"); for (int j = 0; j < tokenizedTerms.length; j++) { if (!(tokenizedTerms[j] == null) && (!(tokenizedTerms[j].equalsIgnoreCase("")))) { SEwords.add(tokenizedTerms[j]); } } } } } File file_thelist = new File(dir + "Javawords.txt"); FileUtils.writeLines(file_thelist, SEwords); return SEwords; } catch (IOException ex) { Logger.getLogger(WebParser.class.getName()).log(Level.SEVERE, null, ex); System.out.print("can not create the content file for SEwords"); return SEwords; } }
From source file:edu.cmu.cs.lti.discoursedb.annotation.brat.io.BratService.java
/** * Generates an empty brat anotation.conf file and registers the provided set of annotation types. * //w ww.ja va 2 s .c o m * @param outputFolder the folder to which the config file should be written * @param annotationTypes a set of annotation types to register in the brat configuration file * @throws IOException if an exception occurs writing the config file */ @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public void generateBratConfig(String outputFolder, Set<String> annotationTypes) throws IOException { Assert.hasText(outputFolder, "The output folder path cannot be empty."); Assert.notNull(annotationTypes, "The set holding annotation types was null. Please pass a (potentially empty) set."); List<String> annotationConf = new ArrayList<>(); annotationConf.add("[relations]"); annotationConf.add("[events]"); annotationConf.add("[attributes]"); annotationConf.add("[entities]"); annotationConf.addAll(annotationTypes); FileUtils.writeLines(new File(outputFolder, "annotation.conf"), annotationConf); }
From source file:edu.ku.brc.specify.tools.datamodelgenerator.DatamodelGenerator.java
@SuppressWarnings("unchecked") protected void addCascadeRule(Class<?> cls, Method method, final String rule) { String import1 = "import org.hibernate.annotations.Cascade;"; //String import2 = "import org.hibernate.annotations.CascadeType;"; try {/*from ww w . j ava2 s . c om*/ File f = new File(srcCodeDir.getAbsoluteFile() + File.separator + cls.getSimpleName() + ".java"); if (!f.exists()) { log.error("Can't locate source file[" + f.getAbsolutePath() + "]"); return; } List<String> strLines = FileUtils.readLines(f); Vector<String> lines = new Vector<String>(); //boolean addedImports = false; boolean fnd = false; boolean passedImport = false; String methodName = method.getName() + "("; for (String line : strLines) { if (!passedImport && line.indexOf("import") > -1) { passedImport = true; } if (!fnd && line.indexOf(import1) > -1) { fnd = true; } /*if (!fnd && !addedImports && passedImport && (line.indexOf("/**") > -1 || line.indexOf("@Entity") > -1)) { lines.add(import1); lines.add(import2); lines.add(""); addedImports = true; }*/ if (line.indexOf(methodName) > -1 && line.indexOf("public") > -1) { lines.add(rule); } lines.add(line); } FileUtils.writeLines(f, lines); } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatamodelGenerator.class, ex); ex.printStackTrace(); } }
From source file:edu.ku.brc.specify.tools.datamodelgenerator.DatamodelGenerator.java
@SuppressWarnings("unchecked") protected void removeCascadeRule(Class<?> cls, Method method) { try {//from www.j a v a2 s . c o m File f = new File(srcCodeDir.getAbsoluteFile() + File.separator + cls.getSimpleName() + ".java"); if (!f.exists()) { log.error("Can't locate source file[" + f.getAbsolutePath() + "]"); return; } List<String> strLines = FileUtils.readLines(f); Vector<String> lines = new Vector<String>(); String methodName = method.getName() + "("; int inx = 0; for (String line : strLines) { if (line.indexOf(methodName) > -1 && line.indexOf("public") > -1) { int i = inx; int stop = i - 10; System.out.println("[" + strLines.get(i) + "]"); while (!StringUtils.contains(strLines.get(i), "@Cascade") && i > stop) { i--; System.out.println("[" + strLines.get(i) + "]"); } if (i < stop || StringUtils.contains(strLines.get(i), "@Cascade")) { lines.remove(i); } } lines.add(line); inx++; } FileUtils.writeLines(f, lines); } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatamodelGenerator.class, ex); ex.printStackTrace(); } }
From source file:fitnesserefactor.FitnesseRefactor.java
public void WriteAllLines(File wfile) throws IOException { FileUtils.writeLines(wfile, AllLines); }
From source file:com.bluexml.side.integration.buildHudson.utils.Utils.java
public static void writeListInFile(File output, List<String> list) throws IOException { FileUtils.writeLines(output, list); }