List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file, String encoding) throws IOException
From source file:io.fabric8.vertx.maven.plugin.SPICombineTest.java
@Test public void testCombineDiffSPI() throws Exception { File jar1 = new File("target/testCombineDiffSPI.jar"); File jar2 = new File("target/testCombineDiffSPI2.jar"); File jar3 = new File("target/testCombineDiffSPI3.jar"); File jar4 = new File("target/testCombineDiffSPI4.jar"); JavaArchive jarArchive1 = ShrinkWrap.create(JavaArchive.class); jarArchive1.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl"); jarArchive1.as(ZipExporter.class).exportTo(jar1, true); JavaArchive jarArchive2 = ShrinkWrap.create(JavaArchive.class); jarArchive2.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl2"); jarArchive2.as(ZipExporter.class).exportTo(jar2, true); JavaArchive jarArchive3 = ShrinkWrap.create(JavaArchive.class); jarArchive3.addClass(SPICombineTest.class); jarArchive3.as(ZipExporter.class).exportTo(jar3, true); JavaArchive jarArchive4 = ShrinkWrap.create(JavaArchive.class); jarArchive4.addAsServiceProvider("com.test.demo.DemoSPI", "com.test.demo.DemoSPI.impl.DemoSPIImpl4"); jarArchive4.as(ZipExporter.class).exportTo(jar4, true); Set<Artifact> artifacts = new LinkedHashSet<>(); Artifact a1 = new DefaultArtifact("org.acme", "a1", "1.0", "compile", "jar", "", null); a1.setFile(jar1);/* w w w.ja va 2 s.c om*/ Artifact a2 = new DefaultArtifact("org.acme", "a2", "1.0", "compile", "jar", "", null); a2.setFile(jar2); Artifact a3 = new DefaultArtifact("org.acme", "a3", "1.0", "compile", "jar", "", null); a3.setFile(jar3); Artifact a4 = new DefaultArtifact("org.acme", "a4", "1.0", "compile", "jar", "", null); a4.setFile(jar4); artifacts.add(a1); artifacts.add(a2); artifacts.add(a3); artifacts.add(a4); MavenProject project = new MavenProject(); project.setVersion("1.0"); project.setArtifactId("foo"); AbstractVertxMojo mojo = new AbstractVertxMojo() { @Override public void execute() throws MojoExecutionException, MojoFailureException { } }; mojo.setLog(new SystemStreamLog()); Build build = new Build(); build.setOutputDirectory("target/junk"); project.setBuild(build); ServiceFileCombinationConfig config = new ServiceFileCombinationConfig().setProject(project) .setArtifacts(artifacts).setArchive(ServiceUtils.getDefaultFatJar()).setMojo(mojo); combiner.doCombine(config); File merged = new File("target/junk/META-INF/services/com.test.demo.DemoSPI"); assertThat(merged).isFile(); List<String> lines = FileUtils.readLines(merged, "UTF-8"); assertThat(lines).hasSize(3).containsExactly("com.test.demo.DemoSPI.impl.DemoSPIImpl", "com.test.demo.DemoSPI.impl.DemoSPIImpl2", "com.test.demo.DemoSPI.impl.DemoSPIImpl4"); Stream.of(jar1, jar2, jar3, jar4, new File("target/junk")).forEach(FileUtils::deleteQuietly); }
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;// w w w.ja va 2 s. c o 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:com.aurel.track.admin.customize.category.report.execute.ReportBeansToLaTeXConverter.java
/** * Generate the PDF from this Genji document via a Freemarker tagged LaTeX * template.// w w w. j a v a2 s. com * * @param items * @param withHistory * @param locale * @param fullName * @param queryName * @param queryExpression * @param useProjectSpecificID */ public File generatePdf(TWorkItemBean workItem, List<ReportBean> items, boolean withHistory, Locale locale, TPersonBean user, String queryName, String queryExpression, boolean useProjectSpecificID, File template, File templateDir) { prepareDirectories(templateDir); StringBuilder templateBuffer = new StringBuilder(); StringBuilder inlineMacroBuffer = new StringBuilder(); // First remove comments for Freemarker commands from template. // Replace LaTeX escaped characters by their unescaped values try { List<String> lines = FileUtils.readLines(template, "UTF-8"); if (lines.size() < 1) { debugTrace.append("The template file " + template.getName() + " has no lines or does not exist.\n"); debugTrace.append("Make sure you have named the master template file like the tlx package.\n"); } for (String line : lines) { // The following template snippet determines how inline items // are being rendered. // This permits to create live links to the original item, for // example. if (line.startsWith("% %%ITP ")) { line = line.replace("% %%ITP ", ""); inlineMacroBuffer.append(line + CRLF); } else { line = line.replace("\\${", "${").replace("% %%TP", "").replace("\\${", "${").replace("% %%TP", ""); templateBuffer = templateBuffer.append(line + CRLF); } } } catch (IOException e) { LOGGER.error("Could not prepare template file for Freemarker processing " + template.getAbsolutePath()); debugTrace.append(ExceptionUtils.getStackTrace(e) + CRLF); } debugTrace.append("Just before processing by Freemarker: " + CRLF + CRLF + templateBuffer + CRLF); debugTrace.append(templateBuffer + CRLF); // Create the context map for Freemarker using the result set. Map<String, Object> context = fillFreemarkerContext(workItem, items, user, locale, inlineMacroBuffer); // Create the LaTeX file using the Freemarker enriched LaTeX template // file File latexFile = createProcessedLaTeXFile(context, templateBuffer, template.getName()); try { Thread.sleep(1000); } catch (Exception ex) { LOGGER.debug(ExceptionUtils.getStackTrace(ex), ex); } // Run twice to get labels and figures right int exitValue = runPdflatex(new File(latexTmpDir), latexFile, 1); exitValue = runPdflatex(new File(latexTmpDir), latexFile, 2); String pdf = latexFile.getAbsolutePath().replace(".tex", ".pdf"); if (exitValue == -99) { File pdfFile = new File(pdf); try { FileUtils.copyFile(HandleHome.getMissingLaTeXPdf(), pdfFile); } catch (Exception ex) { LOGGER.error("Problem writing missing LaTeX information.", ex); } return pdfFile; } File pdfFile = new File(pdf); if (!pdfFile.exists() || pdfFile.length() < 10 || exitValue != 0) { try { createDebugInfoPdf(pdf, latexFile); } catch (Exception e) { LOGGER.error(e.getMessage()); } } return new File(pdf); }
From source file:fm.last.commons.test.LastAssertions.java
/** * Asserts that the contents of the files are equivalent - i.e. the same lines but not necessarily in the same order. * This allows you to compare files with contents that might be sorted differently. * // ww w . ja v a2 s.c o m * @param expected File containing expected data. * @param expectedFileEncoding Encoding of expected file. * @param actual File to compare. * @param actualFileEncoding Encoding of actual file. * @throws IOException If an error occurs comparing the file contents. */ public static void assertFilesEquivalent(File expected, Charset expectedFileEncoding, File actual, Charset actualFileEncoding) throws IOException { expectedFileEncoding = resolveToDefault(expectedFileEncoding); actualFileEncoding = resolveToDefault(actualFileEncoding); List<String> expectedLines = FileUtils.readLines(expected, expectedFileEncoding); List<String> actualLines = FileUtils.readLines(actual, actualFileEncoding); int expectedLineCount = expectedLines.size(); int actualLineCount = actualLines.size(); Collection<String> difference; if (expectedLineCount >= actualLineCount) { difference = CollectionUtils.subtract(expectedLines, actualLines); } else { difference = CollectionUtils.subtract(actualLines, expectedLines); } assertEquals("Unexpected difference: " + difference, 0, difference.size()); }
From source file:egovframework.rte.fdl.filehandling.FilehandlingServiceTest.java
/** * @throws Exception//from www .ja va2s. c o m */ @SuppressWarnings("unchecked") @Test public void testReadFile() throws Exception { if (!EgovFileUtil.isExistsFile(filename)) EgovFileUtil.writeFile(filename, text, "UTF-8"); assertEquals(EgovFileUtil.readFile(new File(filename), "UTF-8"), text); //log.debug(EgovFileUtil.readTextFile(filename, false)); List<String> lines = FileUtils.readLines(new File(filename), "UTF-8"); log.debug(lines.toString()); String string = lines.get(0); assertEquals(text, string); }
From source file:com.thoughtworks.go.plugin.infra.service.DefaultPluginLoggingServiceIntegrationTest.java
private void assertMessageInLog(File pluginLogFile, String expectedLoggingLevel, String loggerName, String expectedLogMessage) throws Exception { List linesInLog = FileUtils.readLines(pluginLogFile, Charset.defaultCharset()); for (Object line : linesInLog) { if (((String) line).matches(String.format("^.*%s\\s+\\[%s\\] %s:.* - %s$", expectedLoggingLevel, Thread.currentThread().getName(), loggerName, expectedLogMessage))) { return; }/*from w w w .j ava 2 s. com*/ } fail(String.format("None of the lines matched level:%s message:'%s'. Lines were: %s", expectedLoggingLevel, expectedLogMessage, linesInLog)); }
From source file:de.unidue.ltl.flextag.core.reports.adapter.cv.CvAbstractAvgKnownUnknownAccuracyReport.java
protected List<String> readPredictions(File id2o) throws IOException { List<String> out = new ArrayList<>(); Map<String, String> mapping = new HashMap<>(); for (String l : FileUtils.readLines(id2o, "utf-8")) { if (l.startsWith("#labels")) { loadMapping(l, mapping);/*from w w w .jav a2 s.c o m*/ } if (l.startsWith("#")) { continue; } if (l.trim().isEmpty()) { continue; } int lastIndexOf = l.lastIndexOf("="); String v = l.substring(lastIndexOf + 1); String[] split2 = v.split(";"); String g = mapping.get(split2[0]); String p = mapping.get(split2[1]); out.add(g + " " + p); } return out; }
From source file:edu.monash.merc.util.file.DMFileUtils.java
public static List<String> readLines(File file) { List<String> lines = new ArrayList<String>(); try {/* w w w .j a v a 2s. c om*/ lines = FileUtils.readLines(file, "utf-8"); } catch (Exception ex) { throw new DMFileException(ex); } return lines; }
From source file:com.hortonworks.streamline.streams.service.TopologyTestRunResource.java
private Response getEventsOfTestRunTopologyHistory(Long topologyId, Long historyId, String componentName) throws IOException { File eventLogFile = getEventLogFile(topologyId, historyId); List<String> lines = FileUtils.readLines(eventLogFile, ENCODING_UTF_8); Stream<Map<String, Object>> eventsStream = lines.stream().map(line -> { try {//from w w w .j av a 2 s .c o m return objectMapper.readValue(line, new TypeReference<Map<String, Object>>() { }); } catch (IOException e) { throw new RuntimeException(e); } }); if (!StringUtils.isEmpty(componentName)) { eventsStream = eventsStream.filter(event -> { String eventComponentName = (String) event.get("componentName"); return eventComponentName != null && eventComponentName.equals(componentName); }); } return WSUtils.respondEntities(eventsStream.collect(toList()), OK); }
From source file:com.grossbart.jslim.JSlimRunner.java
/** * Read in the externs file if one had been supplied and add the extern references to * the compiler./*from w ww. ja va2s . co m*/ * * @param slim the compiler * * @exception IOException * if there's an error reading the externs file */ private void readExterns(JSlim slim) throws IOException { for (String f : m_externs) { File file = new File(f); List<String> externs = FileUtils.readLines(file, m_charset); for (String extern : externs) { slim.addExtern(extern); } } }