Example usage for org.apache.commons.io IOUtils readLines

List of usage examples for org.apache.commons.io IOUtils readLines

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils readLines.

Prototype

public static List readLines(Reader input) throws IOException 

Source Link

Document

Get the contents of a Reader as a list of Strings, one entry per line.

Usage

From source file:com.redhat.red.offliner.ftest.fixture.TestContentGenerator.java

public TestContentGenerator() throws IOException {
    words = IOUtils.readLines(Thread.currentThread().getContextClassLoader().getResourceAsStream("words.txt"));
}

From source file:com.jgui.ttscrape.htmlunit.FetchController.java

/**
 * Read the previously loaded results./*ww w  .jav a2 s .  c  o m*/
 */
public void read() {
    try {
        int total = 28;
        mode = "Read";

        ArrayList<Show> shows = new ArrayList<Show>();
        for (int i = 1; i <= total; i++) {
            File f = new File("results/shows" + i + ".txt");
            if (f.exists()) {
                FileReader showreader = new FileReader(f);
                List<String> lines = IOUtils.readLines(showreader);
                for (String s : lines) {
                    Show show = Show.fromString(s);
                    shows.add(show);
                }
            }
            progress = (double) i / (double) total;
            notifier.notifyClient("progress", "value", String.valueOf((int) (100.0 * ((double) i) / 28.0)),
                    "mode", mode);
        }
        Collections.sort(shows, new Comparator<Show>() {
            @Override
            public int compare(Show arg0, Show arg1) {
                return arg0.getStartTime().compareTo(arg1.getStartTime());
            }
        });

        HashSet<Long> prev = new HashSet<Long>();
        processShows(prev, shows);
    } catch (IOException ex) {
        logger.error("failed to read", ex);
    }
}

From source file:com.sfs.ucm.service.LogViewService.java

/**
 * Read log file and return as list of lines
 * //from   w  ww  .  j  a  va  2  s  . c  o m
 * @param filepath
 * @return list of lines
 * @throws UCMException
 */
public List<String> readLogFile(final String filepath) throws UCMException {

    List<String> lines = new ArrayList<String>();

    try {
        // use buffering
        InputStream fin = new FileInputStream(filepath);
        lines = IOUtils.readLines(fin);

        fin.close();
    } catch (IOException e) {
        logger.error("Cannot read logfile. {}", e.getMessage());
        throw new UCMException(e);
    }

    return lines;
}

From source file:net.sourceforge.atunes.kernel.modules.player.mplayer.MPlayerEngine.java

@Override
public boolean isEngineAvailable() {
    InputStream in = null;//from  w w w  .  j a v  a2s. com
    try {
        // Processes in Windows need to read input stream, if not process is
        // blocked
        // so read input stream
        String command = getOsManager().getPlayerEngineCommand(this);
        if (command != null) {
            Process testEngineProcess = new ProcessBuilder(command).start();
            in = testEngineProcess.getInputStream();
            IOUtils.readLines(in);
            int rc = testEngineProcess.waitFor();
            return rc == 0;
        }
    } catch (IOException e) {
        Logger.error(e);
    } catch (InterruptedException e) {
        Logger.error(e);
    } finally {
        ClosingUtils.close(in);
    }
    return false;
}

From source file:net.sf.reportengine.out.TestHtmlReportOutput.java

/**
 * Test method for/*from  ww  w. ja v  a  2s . co m*/
 * {@link net.sf.reportengine.out.AbstractFreemarkerReportOutput#close()}.
 */
@Test
public void testNonClosedWriter() throws IOException {
    final String OUTPUT_PATH = "./target/TestClosingWriter.html";
    FileWriter fileWriter = new FileWriter(OUTPUT_PATH);
    HtmlReportOutput classUnderTest = new HtmlReportOutput(fileWriter, false);
    classUnderTest.open();
    classUnderTest.output("emptyLine.ftl");
    classUnderTest.close();

    // at this point the writer should be already closed
    fileWriter.write("\nthis text has been added after HtmlReportOutput has been closed");
    fileWriter.flush();
    fileWriter.close();

    List<String> lines = IOUtils.readLines(new FileReader(OUTPUT_PATH));
    assertEquals(3, lines.size());
    assertEquals("<br/>", lines.get(0));
    assertEquals("<br/>", lines.get(1));
    assertEquals("this text has been added after HtmlReportOutput has been closed", lines.get(2));
}

From source file:cn.guoyukun.spring.utils.forbidden.ForbiddenWordUtils.java

private static void loadForbiddenWords(byte[] fileCBytes) throws IOException {
    Reader reader = null;//w  w  w .ja va 2s .  c o m
    try {
        reader = new BufferedReader(
                new InputStreamReader(new ByteArrayInputStream(fileCBytes), Constants.ENCODING));
        List<String> forbiddenWordsStrList = IOUtils.readLines(reader);
        forbiddenWords = Lists.newArrayList();
        for (int i = forbiddenWordsStrList.size() - 1; i >= 0; i--) {
            String forbiddenWord = forbiddenWordsStrList.get(i).trim();
            if (forbiddenWord.length() == 0 || forbiddenWord.startsWith("#")) {
                continue;
            } else {
                forbiddenWords.add(Pattern.compile(forbiddenWord));
            }
        }
    } catch (Exception e) {
        LOGGER.error("load forbidden words failed", e);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:cz.pichlik.goodsentiment.server.handler.EventAggregatorTest.java

@Test
public void idIsPresent() throws Exception {
    File resultFile = aggregateSingle();
    try (FileReader fr = new FileReader(resultFile)) {
        List<String> result = IOUtils.readLines(fr);
        assertThat(result, hasItems(startsWith("0")));
    }//from w w w .  ja v a2  s.  c  o  m
}

From source file:de.rnd7.libtvdb.util.EpisodeUtil.java

private static List<String> load(final String name) {
    try (InputStream excludes = EpisodeUtil.class.getResourceAsStream(name);) {
        return IOUtils.readLines(excludes);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    } finally {/*  www  .  ja  v a  2  s  .c  o  m*/

    }
}

From source file:de.viaboxx.nlstools.tasks.CopyBundlesTask.java

/**
 * @param controlFile//from w ww.ja  v  a2  s. com
 * @return key = plain name.xml, value = xml-bundle file
 * @throws IOException
 */
static Map<String, File> readControlFileMapping(File controlFile) throws IOException {
    FileReader reader = new FileReader(controlFile);
    List<String> controlFileContent = IOUtils.readLines(reader);
    reader.close();

    Map<String, File> controlFileMapping = new HashMap(controlFileContent.size());
    for (String line : controlFileContent) {
        line = line.trim();
        if (line.length() > 0) {
            int i = line.lastIndexOf('/');
            String name = line.substring(i + 1);
            controlFileMapping.put(name, new File(controlFile.getParent(), line));
        }
    }
    return controlFileMapping;
}

From source file:brut.androlib.src.SmaliBuilder.java

private void buildFile(String fileName, DexBuilder dexBuilder) throws AndrolibException, IOException {
    File inFile = new File(mSmaliDir, fileName);
    InputStream inStream = new FileInputStream(inFile);

    if (fileName.endsWith(".smali")) {
        try {/*from  www.  ja  v a2 s  .  com*/
            if (!SmaliMod.assembleSmaliFile(inFile, dexBuilder, false, false)) {
                throw new AndrolibException("Could not smali file: " + fileName);
            }
        } catch (IOException | RecognitionException ex) {
            throw new AndrolibException(ex);
        }
        return;
    }
    if (!fileName.endsWith(".java")) {
        LOGGER.warning("Unknown file type, ignoring: " + inFile);
        return;
    }

    StringBuilder out = new StringBuilder();
    List<String> lines = IOUtils.readLines(inStream);

    if (!mDebug) {
        final String[] linesArray = lines.toArray(new String[0]);
        for (int i = 1; i < linesArray.length - 1; i++) {
            out.append(linesArray[i].split("//", 2)[1]).append('\n');
        }
    } else {
        lines.remove(lines.size() - 1);
        ListIterator<String> it = lines.listIterator(1);

        out.append(".source \"").append(inFile.getName()).append("\"\n");
        while (it.hasNext()) {
            String line = it.next().split("//", 2)[1].trim();
            if (line.isEmpty() || line.charAt(0) == '#' || line.startsWith(".source")) {
                continue;
            }
            if (line.startsWith(".method ")) {
                it.previous();
                DebugInjector.inject(it, out);
                continue;
            }

            out.append(line).append('\n');
        }
    }

    try {
        if (!SmaliMod.assembleSmaliFile(out.toString(), dexBuilder, false, false, inFile)) {
            throw new AndrolibException("Could not smali file: " + fileName);
        }
    } catch (IOException | RecognitionException ex) {
        throw new AndrolibException(ex);
    }
}