List of usage examples for org.apache.commons.io FileUtils writeLines
public static void writeLines(File file, Collection lines, String lineEnding) throws IOException
toString()
value of each item in a collection to the specified File
line by line. From source file:com.clov4r.moboplayer.android.nil.codec.SubtitleJni.java
/** * ?????/* w ww.ja v a 2 s . c o m*/ * * @param filePath * @param index * @return */ public int openSubtitleFile_2(String filePath, int index, int subtiltle_index) { String charSet = getFilecharset(new File(filePath)); if (!charSet.equals("UTF-8")) { try { String tempPath = filePath.substring(0, filePath.length() - 4) + "mobo_temp_utf-8.srt"; File tempFile = new File(tempPath); if (!tempFile.exists()) { FileUtils.writeLines(tempFile, "UTF-8", FileUtils.readLines(new File(filePath), charSet)); } return openSubtitleFileInJNI2(tempPath, index, subtiltle_index); } catch (Exception e) { e.printStackTrace(); } } return openSubtitleFileInJNI2(filePath, index, subtiltle_index); }
From source file:jp.igapyon.selecrawler.SeleCrawlerWebContentGetter.java
public void processDevice(final String deviceName) throws IOException { System.err.println("[selecrawler] Launch Chrome. UA:" + deviceName); final SimpleChromeWrapper chrome = new SimpleChromeWrapper(settings.getPathChromeDriver(), deviceName, settings.getPathUserDataDir()); chrome.open();/*w ww. j a v a 2s . co m*/ int getcounter = 0; System.err.println( "[selecrawler] Load url list file: " + new File(settings.getPathUrllisttTxt()).getCanonicalPath()); System.err.println("[selecrawler] Target dir: " + new File(settings.getPathTargetDir()).getCanonicalPath()); final List<String> urls = FileUtils.readLines(new File(settings.getPathUrllisttTxt()), "UTF-8"); for (String urlLookup : urls) { if (getcounter >= 10) { // refresh chrome instance getcounter = 0; chrome.close(); chrome.open(); } final File outputFile = getFileHtml(deviceName, urlLookup); if (outputFile.getParentFile().exists() == false) { outputFile.getParentFile().mkdirs(); } final File outputMetaFile = new File(outputFile.getParentFile(), outputFile.getName() + SeleCrawlerConstants.EXT_SC_URL); final File outputLogFile = new File(outputFile.getParentFile(), outputFile.getName() + SeleCrawlerConstants.EXT_SC_LOG); if (outputMetaFile.exists()) { if (settings.isDebug()) { System.err.println("[selecrawler] skip(cache): " + urlLookup); } continue; } System.err.println("[selecrawler] fetch web: " + urlLookup); chrome.getDriver().get(urlLookup); { // check wait settings. final String urlActual = chrome.getDriver().getCurrentUrl(); for (String regex : settings.getUrllistWaitRegex()) { final Pattern pat = Pattern.compile(regex); final Matcher mat = pat.matcher(urlActual); if (mat.find()) { try { System.out.println("waiting browser operation"); Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } } } } final String contents = chrome.getDriver().getPageSource(); FileUtils.writeStringToFile(outputFile, contents, "UTF-8"); FileUtils.writeLines(outputLogFile, "UTF-8", chrome.getLogEntries()); // write meta finally. { final List<String> metaUrlList = new ArrayList<String>(); metaUrlList.add(urlLookup); metaUrlList.add(chrome.getDriver().getCurrentUrl()); FileUtils.writeLines(outputMetaFile, "UTF-8", metaUrlList); } getcounter++; try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } chrome.close(); }
From source file:aes.pica.touresbalon.tb_serviciosbolivariano.ServiciosBolivarianos.java
@Override public boolean crearReserva(String ordenId, String nombres, String apellidos, String fechaSalida, List<ViajeVO> listViajes, boolean sobreEscribir) { String nombreArchivo = Constantes.NAME_RESERVAS + ordenId + Constantes.CSV_FILE; List<String> lineasArchivo = new ArrayList<>(); for (ViajeVO v : listViajes) { lineasArchivo.add(apellidos.toUpperCase() + "," + nombres.toUpperCase() + "," + fechaSalida.toUpperCase() + "," + v.getNumViaje() + "," + v.getNumSilla() + "," + "A,"); }//from w w w . ja v a2 s. c om try { FileUtils.writeLines(new File(rutaReservas, nombreArchivo), lineasArchivo, sobreEscribir); return true; } catch (IOException ex) { System.err.println("Error creando archivo de reservas"); System.err.println(ex.toString()); } return false; }
From source file:com.github.ipaas.ideploy.agent.util.SVNUtil.java
/** * // ww w .ja va2s . com * @param logs * @param destFile */ private static void writeLogToFile(Collection<SVNLog> logs, File destFile) throws Exception { if (logs == null || logs.isEmpty()) { return; } if (!destFile.exists()) { destFile.createNewFile(); } List<String> contents = new LinkedList<String>(); for (SVNLog e : logs) { contents.add(e.toSimpleString()); } FileUtils.writeLines(destFile, contents, false); }
From source file:com.anrisoftware.sscontrol.scripts.locale.ubuntu_12_04.Ubuntu_12_04_InstallLocale.java
private void writeLocales(File file, Charset charset, List<String> lines) throws ScriptException { try {//from w ww. ja va2 s . c om FileUtils.writeLines(file, charset.name(), lines); } catch (IOException e) { throw log.errorAttachLocale(this, e, file); } }
From source file:jp.igapyon.selecrawler.SeleCrawlerWebContentAnalyzer.java
public void processFile(final File file, final String urlString) throws IOException { final List<String> anchorList = new ArrayList<String>(); final List<String> headList = new ArrayList<String>(); final List<String> scriptSrcList = new ArrayList<String>(); final String contents = FileUtils.readFileToString( new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_NORMAL), "UTF-8"); final Document document = SimpleMyXmlUtil.string2Document(contents); {// www . ja va 2s . c o m final String title = SimpleMyXmlUtil.getXPathString(document, "/html/head/title/text()"); if (title != null && title.trim().length() > 0) { headList.add("title: " + title); } } { final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "/html/head/meta"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleMeta = (Element) nodes.item(index); headList.add("meta:"); final NamedNodeMap nnm = eleMeta.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); headList.add(" " + attr.getName() + " [" + attr.getValue() + "]"); } } } } { final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "/html/head/link"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleMeta = (Element) nodes.item(index); headList.add("link:"); final NamedNodeMap nnm = eleMeta.getAttributes(); for (int indexNnm = 0; indexNnm < nnm.getLength(); indexNnm++) { final Attr attr = (Attr) nnm.item(indexNnm); headList.add(" " + attr.getName() + " [" + attr.getValue() + "]"); } } } } { // search anchor with href final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "//a"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleAnchor = (Element) nodes.item(index); String href = eleAnchor.getAttribute("href"); href = adjustAnchorUrl(href, urlString); if (href == null) { continue; } anchorList.add(href); } } } { // search script final NodeList nodes = SimpleMyXmlUtil.getXPathNodeList(document, "//script"); for (int index = 0; index < nodes.getLength(); index++) { if (nodes.item(index) instanceof Element) { final Element eleScript = (Element) nodes.item(index); String srcString = eleScript.getAttribute("src"); srcString = adjustAnchorUrl(srcString, urlString); if (srcString == null) { continue; } scriptSrcList.add(srcString); } } } { final File fileMetaAnchor = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_ANCHOR); FileUtils.writeLines(fileMetaAnchor, "UTF-8", anchorList); } { final File fileMetaHead = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_HEAD); FileUtils.writeLines(fileMetaHead, "UTF-8", headList); } { final File fileScriptSrc = new File(file.getParentFile(), file.getName() + SeleCrawlerConstants.EXT_SC_SCRIPTSRC); FileUtils.writeLines(fileScriptSrc, "UTF-8", scriptSrcList); } }
From source file:com.opoopress.maven.plugins.plugin.ThemeMojo.java
private void updateSiteConfigurationFile(ConfigImpl config, String currentThemeName, String newThemeName) throws MojoFailureException { if (currentThemeName != null) { File file = new File(config.getBasedir(), "config.yml"); if (file.exists()) { try { List<String> lines = FileUtils.readLines(file, "UTF-8"); int lineNumber = -1; for (int i = 0; i < lines.size(); i++) { if (lines.get(i).startsWith("theme: ")) { lineNumber = i;/*from w ww .jav a 2 s . co m*/ break; } } if (lineNumber != -1) { getLog().debug("Change theme to '" + newThemeName + "' in file:" + file); lines.set(lineNumber, "theme: '" + newThemeName + "'"); FileUtils.writeLines(file, "UTF-8", lines); return; } } catch (IOException e) { throw new MojoFailureException("Update configuration file failed: " + e.getMessage(), e); } } } getLog().debug("Changing config file 'config-theme.yml'."); File themeConfigFile = new File(config.getBasedir(), "config-theme.yml"); try { FileUtils.writeStringToFile(themeConfigFile, "theme: '" + name + "'"); } catch (IOException e) { throw new MojoFailureException("Change theme config file failed.", e); } }
From source file:eu.europeana.sounds.vocabulary.genres.music.OnbMimoMappingTest.java
@Test public void mergeEnrichmentsAndRemoveOnbMimoMappingDuplicates() throws IOException, EuropeanaApiProblem { Map<String, String> mapIdToLine = new HashMap<String, String>(); List<String> enrichedIds = new ArrayList<String>(); List<String> resultingLines = new ArrayList<String>(); // read variations and extract ID in form <EuropeanaId_matchLink> extractMappingIds(ENRICHED_INSTRUMENT_VARIATIONS_V1_FILE_PATH, enrichedIds, mapIdToLine); // read shortenings and extract ID in form <EuropeanaId_matchLink> extractMappingIds(ENRICHED_INSTRUMENT_SHORTENINGS_V1_FILE_PATH, enrichedIds, mapIdToLine); // read existing input extentions and extract ID in form <EuropeanaId_matchLink> File outputFile = new File(OUTPUT_ENRICHED_INSTRUMENT_LIST_FILE_PATH); List<String> inputEnrichedIds = new ArrayList<String>(); String headerLine = extractMappingIds(INPUT_ENRICHED_INSTRUMENT_LIST_FILE_PATH, inputEnrichedIds, mapIdToLine);/*from ww w . j a v a2 s .c o m*/ // identifying by ID in form <EuropeanaId_matchLink>, write out additional mappings // from variations and shortenings in output file resultingLines.add(headerLine); // header for (String enrichedIdLine : enrichedIds) { if (!inputEnrichedIds.contains(enrichedIdLine) && (!resultingLines.contains(mapIdToLine.get(enrichedIdLine)))) { resultingLines.add(mapIdToLine.get(enrichedIdLine)); } } FileUtils.writeLines(outputFile, "UTF-8", resultingLines); }
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 . j a va 2s . c om*/ // 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.t2ti.plugins.sped.fiscal.SpedFiscal.java
public void geraArquivoTxt(File arquivo) throws Exception { getBloco9().getListaRegistro9900().clear(); //bloco 0/*from w ww . j av a2 s .c o m*/ getLinhasArquivo().add(getBloco0().writeRegistro0000()); incluiRegistro9900("0000", 1); getLinhasArquivo().add(getBloco0().writeRegistro0001()); incluiRegistro9900("0001", 1); incluiRegistro9900("0005", 1); if (getBloco0().getQuantidadeRegistros0015() > 0) { incluiRegistro9900("0015", getBloco0().getQuantidadeRegistros0015()); } incluiRegistro9900("0100", 1); if (getBloco0().getQuantidadeRegistros0150() > 0) { incluiRegistro9900("0150", getBloco0().getQuantidadeRegistros0150()); if (getBloco0().getQuantidadeRegistros0175() > 0) { incluiRegistro9900("0175", getBloco0().getQuantidadeRegistros0175()); } } if (getBloco0().getQuantidadeRegistros0190() > 0) { incluiRegistro9900("0190", getBloco0().getQuantidadeRegistros0190()); } if (getBloco0().getQuantidadeRegistros0200() > 0) { incluiRegistro9900("0200", getBloco0().getQuantidadeRegistros0200()); if (getBloco0().getQuantidadeRegistros0205() > 0) { incluiRegistro9900("0205", getBloco0().getQuantidadeRegistros0205()); } if (getBloco0().getQuantidadeRegistros0206() > 0) { incluiRegistro9900("0206", getBloco0().getQuantidadeRegistros0206()); } if (getBloco0().getQuantidadeRegistros0220() > 0) { incluiRegistro9900("0220", getBloco0().getQuantidadeRegistros0220()); } } if (getBloco0().getQuantidadeRegistros0300() > 0) { incluiRegistro9900("0300", getBloco0().getQuantidadeRegistros0300()); } if (getBloco0().getQuantidadeRegistros0400() > 0) { incluiRegistro9900("0400", getBloco0().getQuantidadeRegistros0400()); } if (getBloco0().getQuantidadeRegistros0450() > 0) { incluiRegistro9900("0450", getBloco0().getQuantidadeRegistros0450()); } if (getBloco0().getQuantidadeRegistros0460() > 0) { incluiRegistro9900("0460", getBloco0().getQuantidadeRegistros0460()); } if (getBloco0().getQuantidadeRegistros0500() > 0) { incluiRegistro9900("0500", getBloco0().getQuantidadeRegistros0500()); } if (getBloco0().getQuantidadeRegistros0600() > 0) { incluiRegistro9900("0600", getBloco0().getQuantidadeRegistros0600()); } getLinhasArquivo().add(getBloco0().writeRegistro0990()); incluiRegistro9900("0990", 1); //bloco C getLinhasArquivo().add(getBlocoC().writeRegistroC001()); incluiRegistro9900("C001", 1); if (getBlocoC().getQuantidadeRegistrosC100() > 0) { incluiRegistro9900("C100", getBlocoC().getQuantidadeRegistrosC100()); if (getBlocoC().getQuantidadeRegistrosC110() > 0) { incluiRegistro9900("C110", getBlocoC().getQuantidadeRegistrosC110()); if (getBlocoC().getQuantidadeRegistrosC114() > 0) { incluiRegistro9900("C114", getBlocoC().getQuantidadeRegistrosC114()); } } if (getBlocoC().getQuantidadeRegistrosC190() > 0) { incluiRegistro9900("C190", getBlocoC().getQuantidadeRegistrosC190()); } } if (getBlocoC().getQuantidadeRegistrosC300() > 0) { incluiRegistro9900("C300", getBlocoC().getQuantidadeRegistrosC300()); if (getBlocoC().getQuantidadeRegistrosC310() > 0) { incluiRegistro9900("C310", getBlocoC().getQuantidadeRegistrosC310()); } if (getBlocoC().getQuantidadeRegistrosC320() > 0) { incluiRegistro9900("C320", getBlocoC().getQuantidadeRegistrosC320()); if (getBlocoC().getQuantidadeRegistrosC321() > 0) { incluiRegistro9900("C321", getBlocoC().getQuantidadeRegistrosC321()); } } } if (getBlocoC().getQuantidadeRegistrosC350() > 0) { incluiRegistro9900("C350", getBlocoC().getQuantidadeRegistrosC350()); if (getBlocoC().getQuantidadeRegistrosC370() > 0) { incluiRegistro9900("C370", getBlocoC().getQuantidadeRegistrosC370()); } if (getBlocoC().getQuantidadeRegistrosC390() > 0) { incluiRegistro9900("C390", getBlocoC().getQuantidadeRegistrosC390()); } } if (getBlocoC().getQuantidadeRegistrosC400() > 0) { incluiRegistro9900("C400", getBlocoC().getQuantidadeRegistrosC400()); if (getBlocoC().getQuantidadeRegistrosC405() > 0) { incluiRegistro9900("C405", getBlocoC().getQuantidadeRegistrosC405()); if (getBlocoC().getQuantidadeRegistrosC420() > 0) { incluiRegistro9900("C420", getBlocoC().getQuantidadeRegistrosC420()); if (getBlocoC().getQuantidadeRegistrosC425() > 0) { incluiRegistro9900("C425", getBlocoC().getQuantidadeRegistrosC425()); } } if (getBlocoC().getQuantidadeRegistrosC460() > 0) { incluiRegistro9900("C460", getBlocoC().getQuantidadeRegistrosC460()); if (getBlocoC().getQuantidadeRegistrosC470() > 0) { incluiRegistro9900("C470", getBlocoC().getQuantidadeRegistrosC470()); } } if (getBlocoC().getQuantidadeRegistrosC490() > 0) { incluiRegistro9900("C490", getBlocoC().getQuantidadeRegistrosC490()); } } } getLinhasArquivo().add(getBlocoC().writeRegistroC990()); incluiRegistro9900("C990", 1); //bloco E getLinhasArquivo().add(getBlocoE().writeRegistroE001()); incluiRegistro9900("E001", 1); if (getBlocoE().getQuantidadeRegistrosE100() > 0) { incluiRegistro9900("E100", getBlocoE().getQuantidadeRegistrosE100()); incluiRegistro9900("E110", 1); if (getBlocoE().getQuantidadeRegistrosE116() > 0) { incluiRegistro9900("E116", getBlocoE().getQuantidadeRegistrosE116()); } } getLinhasArquivo().add(getBlocoE().writeRegistroE990()); incluiRegistro9900("E900", 1); //bloco H getLinhasArquivo().add(getBlocoH().writeRegistroH001()); incluiRegistro9900("H001", 1); getLinhasArquivo().add(getBlocoH().writeRegistroH990()); incluiRegistro9900("H900", 1); //bloco 9 getLinhasArquivo().add(getBloco9().writeRegistro9001()); incluiRegistro9900("9001", 1); incluiRegistro9900("9900", getBloco9().getListaRegistro9900().size() + 2); incluiRegistro9900("9990", 1); incluiRegistro9900("9999", 1); getLinhasArquivo().add(getBloco9().writeRegistro9900()); getLinhasArquivo().add(getBloco9().writeRegistro9990()); getBloco9().getRegistro9999() .setQtdLin(getBloco0().getRegistro0990().getQtdLin0() + getBlocoC().getRegistroC990().getQtdLinC() + getBlocoE().getRegistroE990().getQtdLinE() + getBlocoH().getRegistroH990().getQtdLinH() + getBloco9().getRegistro9990().getQtdLin9()); getLinhasArquivo().add(getBloco9().writeRegistro9999()); FileUtils.writeLines(arquivo, getLinhasArquivo(), ""); }