List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file, String encoding) throws IOException
From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java
/** * @param file// www . j a v a 2 s .c o m */ protected void copyNewLines(final File file) { String dirName = RES_PATH + "values-" + destLocale.getLanguage(); String dstPath = dirName + File.separator + file.getName(); try { List<String> srcLines = (List<String>) FileUtils.readLines(file, "UTF8"); Vector<String> dstLines = new Vector<String>( (List<String>) FileUtils.readLines(new File(dstPath), "UTF8")); int dstCnt = 0; for (int i = 0; i < srcLines.size(); i++) { String srcLine = srcLines.get(i); String dstLine = dstLines.get(dstCnt++); if (StringUtils.contains(srcLine, "<?xml") && StringUtils.contains(dstLine, "<?xml")) continue; if (StringUtils.contains(srcLine, "<res") && StringUtils.contains(dstLine, "<res")) continue; if (StringUtils.contains(srcLine, "</res") && StringUtils.contains(dstLine, "</res")) continue; srcLine = StringUtils.replace(srcLine, "\\ \'", "\\\'"); srcLine = StringUtils.replace(srcLine, "s \\\'", "s\\\'"); dstLine = StringUtils.replace(dstLine, "\\ \'", "\\\'"); dstLine = StringUtils.replace(dstLine, "s \\ \'", "s\\\'"); System.out.println("--- [" + srcLine + "][" + dstLine + "] -- "); if (srcLine.equals(dstLine)) continue; boolean isSrcComment = StringUtils.contains(srcLine, "<!--"); boolean isDstComment = StringUtils.contains(dstLine, "<!--"); String srcKey = !isSrcComment ? getKey(srcLine) : ""; String dstKey = !isDstComment ? getKey(dstLine) : ""; if (srcKey != null && dstKey != null && srcKey.equals(dstKey) && srcKey.length() > 0) continue; dstLines.insertElementAt(srcLine, dstCnt++); } System.out.println("----------------------------"); for (int i = 0; i < srcLines.size(); i++) { String srcLine = srcLines.get(i); String dstLine = dstLines.get(i); srcLine = StringUtils.replace(srcLine, "\\ \'", "\\\'"); srcLine = StringUtils.replace(srcLine, "s \\\'", "s\\\'"); dstLine = StringUtils.replace(dstLine, "\\ \'", "\\\'"); dstLine = StringUtils.replace(dstLine, "s \\ \'", "s\\\'"); System.out.println("--- [" + srcLine + "] " + srcLine.length() + " [" + dstLine + "] " + dstLine.length() + " -- "); } } catch (IOException e) { e.printStackTrace(); } }
From source file:jenkins.security.stapler.StaticRoutingDecisionProvider.java
/** * Loads the data from the disk into this object. * * <p>/* w ww . j a v a 2 s .co m*/ * The constructor of the derived class must call this method. * (If we do that in the base class, the derived class won't * get a chance to set default values.) */ private synchronized void reloadFromUserControlledList() { File file = getConfigFile(); if (!file.exists()) { if ((whitelistSignaturesFromUserControlledList != null && whitelistSignaturesFromUserControlledList.isEmpty()) || (blacklistSignaturesFromUserControlledList != null && blacklistSignaturesFromUserControlledList.isEmpty())) { LOGGER.log(Level.INFO, "No whitelist source file found at " + file + " so resetting user-controlled whitelist"); } whitelistSignaturesFromUserControlledList = new HashSet<>(); blacklistSignaturesFromUserControlledList = new HashSet<>(); return; } LOGGER.log(Level.INFO, "Whitelist source file found at " + file); try { whitelistSignaturesFromUserControlledList = new HashSet<>(); blacklistSignaturesFromUserControlledList = new HashSet<>(); parseFileIntoList(FileUtils.readLines(file, StandardCharsets.UTF_8), whitelistSignaturesFromUserControlledList, blacklistSignaturesFromUserControlledList); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to load " + file.getAbsolutePath(), e); } }
From source file:com.netsteadfast.greenstep.util.SystemFtpClientUtils.java
private static void processText(SystemFtpClientResultObj resultObj) throws Exception { SysFtpTranVO tran = resultObj.getSysFtpTran(); List<SystemFtpClientData> datas = new LinkedList<SystemFtpClientData>(); List<TbSysFtpTranSegm> segms = resultObj.getSysFtpTranSegms(); for (File file : resultObj.getFiles()) { SystemFtpClientData ftpData = new SystemFtpClientData(); List<Map<String, String>> fillDataList = new LinkedList<Map<String, String>>(); logWarnFileSize(file);//from w w w. j av a 2 s . c o m List<String> strLines = FileUtils.readLines(file, resultObj.getSysFtpTran().getEncoding()); if (YesNo.YES.equals(resultObj.getSysFtpTran().getUseSegm())) { for (int i = 0; i < strLines.size(); i++) { String strData = strLines.get(i); if (strData.length() < 1) { logger.warn("The file: " + file.getPath() + " found zero line."); continue; } if (i < tran.getBeginLen()) { // not begin line. continue; } Map<String, String> dataMap = new HashMap<String, String>(); fillStrLine2Map(resultObj.getSysFtpTran(), segms, dataMap, strData); fillDataList.add(dataMap); } } ftpData.setContent(getContent(strLines)); ftpData.setDatas(fillDataList); ftpData.setFile(file); datas.add(ftpData); } resultObj.setDatas(datas); }
From source file:com.github.cereda.arara.rulechecker.RuleUtils.java
public static void updateRules(List<File> files) { // check if the provided list is empty if (files.isEmpty()) { // print error message System.err.println(WordUtils.wrap("Fatal exception: I could not find any rules in " + "the provided directory. I am afraid I won't be " + "be able to continue. Please make sure the " + "provided directory contains at least one rule to " + "be analyzed. The application will halt now.", 60)); }/* w w w.ja v a 2s . com*/ // print header System.out.println(StringUtils.center(" Update report ", 60, "-").concat("\n")); // read each file of the list and extract // each task found for (File file : files) { try { // read each file into a list // of strings List<String> lines = FileUtils.readLines(file, "UTF-8"); // create the potential // output for the updated file List<String> output = new ArrayList<>(); // iterate through each line for (String line : lines) { // only add lines not matching // the task pattern if (!match(line)) { output.add(line); } } // result string String result; // if the sizes are the same, // nothing happened if (lines.size() == output.size()) { // update status result = " Unchanged"; } else { // update the file reference FileUtils.writeLines(file, "UTF-8", output); // update status result = " Updated"; } // build the beginning of the line String line = String.format("- %s ", file.getName()); // generate the full entry line = line.concat(StringUtils.repeat(".", 60 - line.length() - result.length())).concat(result); // print entry System.out.println(line); } catch (IOException exception) { // print error message System.err.println(WordUtils.wrap("Fatal exception: an error was raised while " + "trying to read one of the rules. Please make " + "sure all rules in the provided directory have " + "read permission. I won't be able to continue. " + "The application will halt now.", 60)); System.exit(1); } } }
From source file:com.thoughtworks.go.plugin.infra.service.DefaultPluginLoggingServiceIntegrationTest.java
private void assertNumberOfMessagesInLog(File pluginLogFile, int size) throws Exception { assertThat(FileUtils.readLines(pluginLogFile, Charset.defaultCharset()).size(), is(size)); }
From source file:com.silverpeas.communicationUser.control.CommunicationUserSessionController.java
public String getDiscussion(File fileDiscussion) throws CommunicationUserException { try {/*from ww w .j a v a 2 s. com*/ List<String> lines = FileUtils.readLines(fileDiscussion, "UTF-8"); StringBuilder messages = new StringBuilder(""); for (String line : lines) { messages.append(line).append("\n"); } return messages.toString(); } catch (IOException e) { throw new CommunicationUserException("CommunicationUserSessionController.getDiscussion()", SilverpeasException.ERROR, "root.EX_NO_MESSAGE", e); } }