List of usage examples for org.apache.commons.io IOUtils readLines
public static List readLines(Reader input) throws IOException
Reader
as a list of Strings, one entry per line. From source file:net.sourceforge.atunes.kernel.modules.playlist.PlayListReader.java
/** * This function reads the filenames from the playlist file, trying to find * the ones present in repository, which are returned in a list * /* w ww . j a v a 2 s. co m*/ * @param file * The playlist file * * @return Returns an List of files of the playlist as String. */ List<String> read(final File file) { Timer t = new Timer(); t.start(); FileReader fr = null; try { List<File> repositoryFolders = this.repositoryHandler.getFolders(); fr = new FileReader(file); List<String> fileContent = IOUtils.readLines(fr); List<String> result = new ArrayList<String>(); for (String line : fileContent) { String fullPath = getFileIfExistsInRepository(repositoryFolders, line); if (fullPath != null) { result.add(fullPath); } } Logger.debug("Time to read playlist file: ", t.stop(), " seconds"); return result; } catch (IOException e) { return Collections.emptyList(); } finally { ClosingUtils.close(fr); } }
From source file:com.hortonworks.registries.util.HdfsFileStorageTest.java
@Test public void testUploadJar() throws Exception { Map<String, String> config = new HashMap<>(); config.put(HdfsFileStorage.CONFIG_FSURL, "file:///"); fileStorage.init(config);//from www .j a v a2 s . c om File file = File.createTempFile("test", ".tmp"); file.deleteOnExit(); List<String> lines = Arrays.asList("test-line-1", "test-line-2"); Files.write(file.toPath(), lines, Charset.forName("UTF-8")); String jarFileName = "test.jar"; fileStorage.deleteFile(jarFileName); fileStorage.uploadFile(new FileInputStream(file), jarFileName); InputStream inputStream = fileStorage.downloadFile(jarFileName); List<String> actual = IOUtils.readLines(inputStream); Assert.assertEquals(lines, actual); }
From source file:de.fhg.iais.cortex.guice.abstractModules.AbstractCortexServerModule.java
public AbstractCortexServerModule(Home home) { FileInputStream fis = null;/*from w w w . jav a 2s . c o m*/ this.moduleNameOrder = Lists.newArrayList(); File startServersConfig = home.getResourceLocationAsFile("startServers.txt"); try { fis = new FileInputStream(startServersConfig); for (String line : IOUtils.readLines(fis)) { if (Strings.isNullOrEmpty(line) || line.startsWith("#")) { continue; } this.moduleNameOrder.add(line); } } catch (FileNotFoundException e) { throw new DbcException("Unable to read configuration at " + startServersConfig.getAbsolutePath() + ".", e); } catch (IOException e) { throw new DbcException("Unable to read configuration at " + startServersConfig.getAbsolutePath() + ".", e); } finally { IOUtils.closeQuietly(fis); } }
From source file:net.sourceforge.atunes.kernel.modules.playlist.M3UPlayListReader.java
List<String> read(final File file) { FileReader fr = null;//from w w w . ja va 2 s .c o m try { fr = new FileReader(file); List<String> lines = readUntilFirstUncommentedLine(IOUtils.readLines(fr)); if (!lines.isEmpty()) { String firstLine = lines.get(0); if (isFormatSupported(firstLine)) { return readLines(lines, file.getParent() + this.osManager.getFileSeparator(), isRelativePaths(firstLine)); } } } catch (IOException e) { Logger.error(e); } finally { ClosingUtils.close(fr); } return Collections.emptyList(); }
From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.PluginFileUtils.java
@SuppressWarnings("unchecked") public static List<String> readLines(Class<?> relativeClass, String resourceName) { InputStream inputStream = null; try {//from w w w . j a v a2s . c o m inputStream = relativeClass.getResourceAsStream(resourceName); if (inputStream == null) { throw new RuntimeException("No resource with name [" + resourceName + "] found relative to class [" + relativeClass.getName() + "]."); } return IOUtils.readLines(inputStream); } catch (IOException e) { throw new RuntimeException("Failed to read lines from resource [" + resourceName + "] relative to class [" + relativeClass.getName() + "]."); } finally { try { if (inputStream != null) inputStream.close(); } catch (IOException ignore) { } } }
From source file:framework.GroovyTemplateEngine.java
public void generate(String name, Reader reader, File outputFile) throws FileNotFoundException, IOException { List<String> imports = IOUtils.readLines(Template.class.getResourceAsStream("/imports.groovy")); FileWriter writer = new FileWriter(outputFile); try {// ww w .j ava2 s. c o m for (String line : imports) { writer.append(line).append('\n'); } writer.append("framework.ThreadData data = framework.FrontController.threadData.get()\n"); writer.append("Writer out = data.out\n"); int s = 0; int ch = -1; writer.append("out.write '"); while ((ch = reader.read()) != -1) { if (ch == '<' && s == 0) { s = 1; writer.append("'\n"); } else if (ch == '%' && s == 1) { s = 2; } else if (ch == '#' && s == 2) { s = 7; } else if (s == 1) { s = 0; writer.append("out.write '<"); addChar(writer, s, ch); } else if (ch == '=' && s == 2) { s = 3; writer.append("out.write '' + ("); } else if (s == 2) { s = 6; addChar(writer, s, ch); } else if (ch == '%' && s == 7) { s = 8; } else if (ch == '%' && s == 6) { s = 4; } else if (ch == '%' && s == 3) { s = 5; } else if (ch == '>' && s == 8) { s = 0; writer.append("out.write '"); } else if (ch == '>' && s == 4) { s = 0; writer.append("\nout.write '"); } else if (ch == '>' && s == 5) { s = 0; writer.append(")\nout.write '"); } else if (s == 4) { s = 2; writer.append('%'); } else if (s == 5) { s = 3; writer.append('%'); } else if (ch == '\n') { if (s == 0) { writer.append("\\n'\nout.write '"); } else { writer.append(" "); } s = 0; } else if (ch == '\r') { if (s != 0) { writer.append(" "); } } else if (s != 7) { addChar(writer, s, ch); } } if (s == 0) { writer.append("'"); } } finally { reader.close(); writer.close(); } }
From source file:ch.itemis.xdocker.lib.TestDockerClient.java
@Test public void execStart() throws Exception { String containerName = "generated_serano" + new SecureRandom().nextInt(); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("ls") .withName(containerName).exec(); assertNotNull(container);//from w ww .j a va2s.c om assertNotNull(container.getId()); InputStream response = dockerClient.execStartCmd(container.getId()).exec(null); assertNotNull(response); List<String> res = IOUtils.readLines(response); for (String string : res) { System.out.println(string); } }
From source file:com.inbook.resource.PngSprite.java
@SuppressWarnings("unchecked") private void loadParts() { try (InputStream io = getStream(SPRITE_DESCRIPTOR_EXT)) { List<String> list = IOUtils.readLines(io); for (int i = 0; i < list.size(); i++) { String iconName = list.get(i); positions.put(iconName, i);// w w w . j a v a 2 s. c o m } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:demo.buttso.web.QuoteMakerTest.java
@Test @RunAsClient//from w ww.jav a 2s.c o m public void checkQuoteIsPresent(@ArquillianResource URL contextPath) { String newContext = contextPath.toExternalForm() + "/QuoteServlet"; LOG.info(newContext); InputStream in = null; try { in = new URL(newContext).openStream(); for (String line : IOUtils.readLines(in)) { if (line.contains("quote")) { System.out.println(line); Assert.assertTrue("Quote found", line.contains("quote")); break; } } } catch (Exception e) { Assert.assertFalse("Quote not found", true); } finally { IOUtils.closeQuietly(in); } }
From source file:com.logsniffer.util.grok.GrokAppConfig.java
@Bean public GroksRegistry groksRegistry() throws IOException, GrokException { GroksRegistry registry = new GroksRegistry(); PathMatchingResourcePatternResolver pathMatcher = new PathMatchingResourcePatternResolver(); Resource[] classPathPatterns = pathMatcher.getResources("classpath*:/grok-patterns/*"); Arrays.sort(classPathPatterns, new Comparator<Resource>() { @Override// w w w.j a v a 2 s. c om public int compare(final Resource o1, final Resource o2) { return o1.getFilename().compareTo(o2.getFilename()); } }); LinkedHashMap<String, String[]> grokBlocks = new LinkedHashMap<String, String[]>(); for (Resource r : classPathPatterns) { grokBlocks.put(r.getFilename(), IOUtils.readLines(r.getInputStream()).toArray(new String[0])); } registry.registerPatternBlocks(grokBlocks); return registry; }