Example usage for org.apache.commons.io LineIterator next

List of usage examples for org.apache.commons.io LineIterator next

Introduction

In this page you can find the example usage for org.apache.commons.io LineIterator next.

Prototype

public Object next() 

Source Link

Document

Returns the next line in the wrapped Reader.

Usage

From source file:fr.itinerennes.bundler.tasks.framework.AbstractCountedCsvTask.java

@PostExec
public void prependLineCount() throws IOException {

    LOGGER.debug("Inserting line count at file head: {}", lineCount);

    final File output = getOutputFile();
    final File source = File.createTempFile("itr-", output.getName(), output.getParentFile());
    source.delete();//ww  w  .j av a  2s.c  om
    FileUtils.moveFile(output, source);

    InputStream from = null;
    BufferedWriter to = null;
    try {
        from = new FileInputStream(source);
        to = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), CHARSET));
        to.write(String.valueOf(lineCount));
        to.newLine();
        final LineIterator i = IOUtils.lineIterator(from, CHARSET.name());
        while (i.hasNext()) {
            to.write(i.next());
            to.newLine();
        }
    } finally {
        IOUtils.closeQuietly(from);
        IOUtils.closeQuietly(to);
        FileUtils.deleteQuietly(source);
    }
}

From source file:com.icantrap.collections.dawg.TrieValidationTest.java

@Before
public void before() throws IOException {
    assumeThat(System.getProperty("RUN_VALIDATION"), is("on"));
    LineIterator iter = IOUtils.lineIterator(getClass().getResourceAsStream("/TWL06.txt"), null);
    dawgBuilder = new DawgBuilder();

    while (iter.hasNext())
        dawgBuilder.add(iter.next());

    LineIterator.closeQuietly(iter);//from  ww  w .j  a v  a  2 s  .c o m

    System.out.println("Uncompressed:  " + dawgBuilder.nodeCount() + " nodes");

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    dawgBuilder.build();
    stopWatch.stop();

    System.out.println("Time to compress:  " + stopWatch.getTime() + " ms.");
    System.out.println("Compressed:  " + dawgBuilder.nodeCount() + " nodes");
}

From source file:de.tudarmstadt.lt.lm.service.LtSegProvider.java

@Override
public List<String> splitSentences(String text, String language_code) throws Exception {
    LOG.trace(String.format("Splitting sentences from text: %s", StringUtils.abbreviate(text, 200)));
    List<String> sentences = new ArrayList<String>();

    if (Properties.onedocperline()) {
        LineIterator liter = new LineIterator(new StringReader(text));
        for (String line; (line = liter.hasNext() ? liter.next() : null) != null;)
            split_and_add_sentences(line, sentences);
    } else {/*from   w  w  w  .  j a  v a  2s.c om*/
        split_and_add_sentences(text, sentences);
    }

    LOG.trace(String.format("Split text '%s' into '%d' sentences.", StringUtils.abbreviate(text, 200),
            sentences.size()));
    return sentences;
}

From source file:com.fides.Agent.java

private void dumpPropfileContents(File propFile) {
    LineIterator iter = null;
    try {// w  w  w.  j av a2  s .  co  m
        iter = FileUtils.lineIterator(propFile);
        while (iter.hasNext()) {
            logger.debug(iter.next());
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } finally {
        if (iter != null)
            iter.close();
    }
}

From source file:com.zenika.doclipser.api.DockerClientJavaApi.java

@Override
public void defaultBuildCommand(String eclipseProjectName, String dockerBuildContext) {
    File baseDir = new File(dockerBuildContext);
    InputStream response = dockerClient.buildImageCmd(baseDir).exec();
    StringWriter logwriter = new StringWriter();
    messageConsole.getDockerConsoleOut()
            .println(">>> Building " + dockerBuildContext + "/Dockerfile with default options");
    messageConsole.getDockerConsoleOut().println("");

    try {/*from   w ww  .  j  a  va  2s .  com*/
        messageConsole.getDockerConsoleOut().flush();
        LineIterator itr = IOUtils.lineIterator(response, "UTF-8");
        while (itr.hasNext()) {
            String line = itr.next();
            logwriter.write(line);
            messageConsole.getDockerConsoleOut().println(line);
            messageConsole.getDockerConsoleOut().flush();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(response);
    }

    messageConsole.getDockerConsoleOut().println("");
    messageConsole.getDockerConsoleOut().println("<<< Build ended");
}

From source file:com.icantrap.collections.dawg.TrieValidationTest.java

@Test
public void containsAllWords() throws IOException {
    LineIterator iter = IOUtils.lineIterator(getClass().getResourceAsStream("/TWL06.txt"), null);

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//ww w . j  a  v a2  s. com

    while (iter.hasNext()) {
        String word = iter.next();
        assertTrue("Missing word (" + word + ")", dawgBuilder.contains(word));
    }

    stopWatch.stop();
    System.out.println("Time to query:  " + stopWatch.getTime() + " ms.");

    LineIterator.closeQuietly(iter);
}

From source file:com.sindicetech.siren.demo.bnb.BNBDemo.java

public void index() throws IOException {
    final SimpleIndexer indexer = new SimpleIndexer(indexDir);
    try {/*  w w w.j av  a2 s  .co  m*/
        int counter = 0;
        final LineIterator it = FileUtils.lineIterator(BNB_PATH);
        while (it.hasNext()) {
            final String id = Integer.toString(counter++);
            final String content = (String) it.next();
            logger.info("Indexing document {}", id);
            indexer.addDocument(id, content);
        }
        LineIterator.closeQuietly(it);
        logger.info("Committing all pending documents");
        indexer.commit();
    } finally {
        logger.info("Closing index");
        indexer.close();
    }
}

From source file:com.icantrap.collections.dawg.DawgValidationTest.java

@Test
public void containsAllWords() throws IOException {
    LineIterator iter = IOUtils.lineIterator(getClass().getResourceAsStream("/TWL06.txt"), null);

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from   w  w w  . j  a  v  a 2s.  co m*/

    while (iter.hasNext()) {
        String word = iter.next();
        assertTrue("Missing word (" + word + ")", dawg.contains(word));
    }

    stopWatch.stop();
    System.out.println("Time to query:  " + stopWatch.getTime() + " ms.");

    LineIterator.closeQuietly(iter);
}

From source file:fr.aliacom.obm.common.calendar.MailSendTest.java

private void assertTextCalendarContentTransferEncodingIsCorrect(CalendarEncoding encoding) throws Exception {
    String icsContent = IOUtils.toString(getClass().getResourceAsStream("meetingWithOneAttendee.ics"));
    EventMail eventMail = new EventMail(new InternetAddress("sender@test"),
            ImmutableList.of(newAttendee("attendee1")), SUBJECT, BODY_TEXT, BODY_HTML, icsContent, ICS_METHOD,
            encoding);//from  w  w w  .j  a  v  a  2  s . c  o  m
    String content = writeEventMail(eventMail);
    LineIterator lineIterator = new LineIterator(new StringReader(content));
    boolean textCalendarFound = false;

    while (lineIterator.hasNext()) {
        if (lineIterator.next().contains("Content-Type: text/calendar")) {
            textCalendarFound = true;
            break;
        }
    }

    assertThat(textCalendarFound).isTrue();
    assertThat(lineIterator.next()).contains("Content-Transfer-Encoding: " + encoding.getValue());
}

From source file:com.icantrap.collections.dawg.DawgBuilder.java

/**
 * Adds words from a newline-delimited file using LineIterator.
 *
 * @param wordIter the line iterator/*from w  w w.  j ava  2  s . co m*/
 * @return the builder
 * @see LineIterator
 */
public DawgBuilder add(LineIterator wordIter) {
    while (wordIter.hasNext())
        add(wordIter.next());

    return this;
}