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:org.ow2.proactive.scheduler.authentication.ManageUsersTest.java
private void updateBulkUsers() throws Exception { FileUtils.writeLines(sourceLoginFile, sourceUsers2); FileUtils.writeLines(sourceGroupFile, sourceGroups2); ManageUsers.manageUsers("-" + ManageUsers.UPDATE_OPTION, "-" + ManageUsers.SOURCE_LOGINFILE_OPTION, sourceLoginFile.getAbsolutePath(), "-" + ManageUsers.SOURCE_GROUPFILE_OPTION, sourceGroupFile.getAbsolutePath(), "-" + ManageUsers.LOGINFILE_OPTION, loginFile.getAbsolutePath(), "-" + ManageUsers.GROUPFILE_OPTION, groupFile.getAbsolutePath(), "-" + ManageUsers.KEYFILE_OPTION, publicKeyFile.getAbsolutePath()); validateContents(users2, groups2);/*from www. j a v a2 s . com*/ }
From source file:org.ow2.proactive.scheduler.authentication.ManageUsersTest.java
private void updateBulkUsersLoginFile() throws Exception { FileUtils.writeLines(sourceLoginFile, sourceUsers2); ManageUsers.manageUsers("-" + ManageUsers.UPDATE_OPTION, "-" + ManageUsers.SOURCE_LOGINFILE_OPTION, sourceLoginFile.getAbsolutePath(), "-" + ManageUsers.LOGINFILE_OPTION, loginFile.getAbsolutePath(), "-" + ManageUsers.GROUPFILE_OPTION, groupFile.getAbsolutePath(), "-" + ManageUsers.KEYFILE_OPTION, publicKeyFile.getAbsolutePath()); }
From source file:org.ow2.proactive.scheduler.authentication.ManageUsersTest.java
private void updateBulkUsersGroupFile() throws Exception { FileUtils.writeLines(sourceGroupFile, sourceGroups2); ManageUsers.manageUsers("-" + ManageUsers.UPDATE_OPTION, "-" + ManageUsers.SOURCE_GROUPFILE_OPTION, sourceGroupFile.getAbsolutePath(), "-" + ManageUsers.LOGINFILE_OPTION, loginFile.getAbsolutePath(), "-" + ManageUsers.GROUPFILE_OPTION, groupFile.getAbsolutePath(), "-" + ManageUsers.KEYFILE_OPTION, publicKeyFile.getAbsolutePath()); }
From source file:org.paxle.filter.blacklist.impl.BlacklistFileStore.java
/** * @see org.paxle.filter.blacklist.IBlacklistStore#updateBlacklist(IBlacklist) *///from w w w. j a v a2 s .c om public boolean updateBlacklist(IBlacklist blacklist) throws InvalidBlacklistnameException { this.validateBlacklistname(blacklist.getName()); final File file = new File(this.blacklistDir.getAbsolutePath() + File.separatorChar + blacklist.getName()); if (!file.exists()) { try { FileUtils.touch(file); } catch (IOException e) { e.printStackTrace(); return false; } } if (file.isFile() && file.canWrite()) { try { FileUtils.writeLines(file, blacklist.getPatternList()); this.blacklists.put(blacklist.getName(), blacklist); return true; } catch (IOException e) { e.printStackTrace(); return false; } } return false; }
From source file:org.punksearch.stats.HostStats.java
/** * Utility method to merge all statistics files in a directory created with dump method into one big file. * <p/>/*from w w w .j a v a 2 s. c o m*/ * Dumping into final file may fail in case of permissions or free space problems. In this case the method just * writes warning in the log and returns. Maybe we should throw an exception here, think about (TODO). * * @param inputDirPath Directory to search for statistics files. * @param outFilePath File to dump merged statistics. */ public static void merge(String inputDirPath, String outFilePath) { File dir = new File(inputDirPath); String[] fileNames = dir.list(); List<String> list = new ArrayList<String>(); for (String fileName : fileNames) { if (fileName.startsWith(DUMP_PREFIX) && fileName.endsWith(DUMP_SUFFIX)) { list.add(fileName); } } fileNames = list.toArray(new String[list.size()]); if (fileNames.length > 0) { Arrays.sort(fileNames); String dirPath = dir.getAbsolutePath() + File.separator; List<HostStats> result = parse(dirPath + fileNames[fileNames.length - 1]); if (fileNames.length > 1) { for (int i = fileNames.length - 2; i >= 0; i--) { List<HostStats> curHostStats = parse(dirPath + fileNames[i]); for (HostStats curHS : curHostStats) { boolean found = false; for (HostStats resultHS : result) { if (curHS.compareTo(resultHS) == 0) { found = true; break; } } if (!found) { result.add(curHS); } } } } Collections.sort(result); try { FileUtils.writeLines(new File(outFilePath), result); } catch (IOException e) { log.warn("Can't dump host stats into file (check permissions and free space): " + outFilePath); } } }
From source file:org.punksearch.stats.HostStats.java
/** * Utility method to dump a list of host stats into a file. * <p/>/*from w ww . j a va 2s . c o m*/ * Dumping may fail in case of permissions or free space problems. In this case the method just writes warning in * the log and returns. Maybe we should throw an exception here, think about (TODO). * * @param dirPath Directory where to create new statistics file. * @param hostStats List of host statistics to dump into the file. */ public static void dump(String dirPath, List<HostStats> hostStats) { Collections.sort(hostStats); File dir = new File(dirPath); if (!dir.exists() && !dir.mkdir()) { log.warn("Can't make directory (check permissions and free space): " + dirPath); return; } DateFormat df = new SimpleDateFormat("yyyy.MM.dd-HH.mm.ss"); String fileName = DUMP_PREFIX + df.format(new Date()) + DUMP_SUFFIX; File dumpFile = new File(dirPath + File.separator + fileName); try { FileUtils.writeLines(dumpFile, hostStats); } catch (IOException e) { log.warn("Can't dump host stats into (check permissions and free space): " + dirPath + File.separator + fileName); } }
From source file:org.p_vcd.model.Parameters.java
private void createUserDataDir() throws Exception { if (!this.userDataPath.exists() || !this.userDataPath.isDirectory()) { FileUtils.forceMkdir(this.userDataPath); }//from w w w . j a va2 s .co m if (this.userDataPath.exists() && this.userDataPath.isDirectory()) { File readmeFile = new File(this.userDataPath, "README.txt"); File logFile = new File(this.userDataPath, "console.log"); if (!readmeFile.exists()) { String l1 = "This directory contains data generated by P-VCD."; String l2 = "You can move it to other destination by modifying P-VCD preferences."; FileUtils.writeLines(readmeFile, Arrays.asList(new String[] { l1, l2 })); } setGlobalLogFile(logFile); } }
From source file:org.silverpeas.file.ModifText.java
/** * lance la modification du fichier Attention la modification s'effectue par ligne du fichier *///from ww w .j a va2 s .co m @Override public void executeModification() throws Exception { File inFile = new File(path); List<String> lines = FileUtils.readLines(inFile); List<String> newLines = new ArrayList<String>(lines.size()); for (String line : lines) { newLines.add(analyseLigne(line)); } FileUtils.writeLines(inFile, newLines); // Specifique Linux/Solaris: on met le fichier de script en executable if ((path.endsWith(".sh") || path.endsWith(".csh") || path.endsWith(".ksh")) && IOUtils.DIR_SEPARATOR_UNIX == File.separatorChar) { String[] commande = new String[3]; commande[0] = "/bin/chmod"; commande[1] = "755"; commande[2] = path; Runtime.getRuntime().exec(commande); } }
From source file:org.smigo.species.KitchenGardenAidDataTest.java
@Test(enabled = true) public void testDataIsComplete() throws Exception { List<String> sqlStatement = new ArrayList<>(); String speciesPath = "resources/species.xml"; InputStream stream = PlantList.class.getResourceAsStream("/" + speciesPath); PlantList.initialize(stream);/* w ww . j a va2 s . co m*/ final Collection<Plant> plants = PlantList.getResources().getPlants(); for (Plant plant : plants) { if (plant.getType() == Taxon.Type.FAMILY && getFamily(plant) == null) { sqlStatement.add(0, "INSERT INTO FAMILIES(ID,NAME)VALUES (" + plant.getId() + ",'" + plant.getName() + "');"); } if (plant.getImage() == null) { log.info("No image, not processing " + plant.getType() + plant); continue; } try { final Species species = getSpecies(plant); if (species == null) { sqlStatement.add( "INSERT INTO SPECIES(ID,SCIENTIFIC_NAME,ITEM,ANNUAL,FAMILY_ID,ICONFILENAME) VALUES (" + plant.getId() + ",'" + plant.getName() + "'," + plant.isItem() + ",true" + "," + plant.getFamily().getId() + ",'" + plant.getId() + ".png');"); } else if (species.isAnnual() != (plant.lifetime.getRepetitionYears() == 1)) { log.error("Annual differ:" + plant); } final Map<String, String> translations = plant.getTranslations(); for (Map.Entry<String, String> kgaLangAndTranslation : translations.entrySet()) { final String kgaLang = kgaLangAndTranslation.getKey(); final String kgaTranslation = kgaLangAndTranslation.getValue(); final String smigoTranslation = getVernaculars(plant.getId(), kgaLang); if (kgaTranslation == null) { log.info("KGA translation missing" + plant); } else if (smigoTranslation == null) { sqlStatement .add("INSERT INTO VERNACULARS(SPECIES_ID,VERNACULAR_NAME,LANGUAGE,COUNTRY) VALUES (" + plant.getId() + ",'" + kgaTranslation.replaceAll("'", "''") + "','" + kgaLang + "','');"); } else if (Objects.equals(smigoTranslation, kgaTranslation)) { //looking good } else { log.error("Translation exists but differ kga:" + plant.getId() + kgaLangAndTranslation + " - smigo:'" + getVernaculars(plant.getId(), kgaLang) + "'"); } } } catch (Exception e) { log.error("Could not map plant:" + plant, e); } FileUtils.writeLines(new File("/tmp/data.sql"), sqlStatement); Assert.assertEquals(sqlStatement, new ArrayList<String>(), sqlStatement.toString()); } }
From source file:org.sonar.batch.protocol.output.BatchReportReaderTest.java
@Test public void read_source_lines() throws Exception { BatchReportWriter writer = new BatchReportWriter(dir); File file = writer.getFileStructure().fileFor(FileStructure.Domain.SOURCE, 1); FileUtils.writeLines(file, Lists.newArrayList("line1", "line2")); File sourceFile = new BatchReportReader(dir).readFileSource(1); assertThat(sourceFile).isEqualTo(file); }