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

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

Introduction

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

Prototype

public boolean hasNext() 

Source Link

Document

Indicates whether the Reader has more lines.

Usage

From source file:au.org.ala.names.util.FileUtils.java

public static Set<String> streamToSet(InputStream source, Set<String> resultSet, boolean toLowerCase)
        throws IOException {
    LineIterator lines = getLineIterator(source, "UTF8");
    while (lines.hasNext()) {
        String line = lines.nextLine().trim();
        if (toLowerCase)
            line = line.toLowerCase();/* www. j ava  2 s .  co m*/
        // ignore comments
        if (!ignore(line)) {
            resultSet.add(line);
        }
    }
    return resultSet;
}

From source file:de.tudarmstadt.ukp.dkpro.c4corpus.hadoop.statistics.vocabulary.TopNWordsCorrelation.java

public static LinkedHashMap<String, Integer> loadCorpusToRankedVocabulary(InputStream corpus)
        throws IOException {
    LinkedHashMap<String, Integer> result = new LinkedHashMap<>();

    LineIterator lineIterator = IOUtils.lineIterator(corpus, "utf-8");
    int counter = 0;
    while (lineIterator.hasNext()) {
        String line = lineIterator.next();

        String word = line.split("\\s+")[0];

        result.put(word, counter);/* w w w.j  a  va 2  s  . c  o m*/
        counter++;
    }

    return result;
}

From source file:com.adobe.acs.tools.csv.impl.CsvUtil.java

/**
 * Adds a populated terminating field to the ends of CSV entries.
 * If the last entry in a CSV row is empty, the CSV library has difficulty understanding that is the end of the row.
 *
 * @param is        the CSV file as an inputstream
 * @param separator The field separator//from   w  w  w.j  a v a2  s.c  o  m
 * @param charset   The charset
 * @return An inputstream that is the same as is, but each line has a populated line termination entry
 * @throws IOException
 */
public static InputStream terminateLines(final InputStream is, final char separator, final String charset)
        throws IOException {

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(baos);

    final LineIterator lineIterator = IOUtils.lineIterator(is, charset);

    while (lineIterator.hasNext()) {
        String line = StringUtils.stripToNull(lineIterator.next());

        if (line != null) {
            line += separator + TERMINATED;
            printStream.println(line);
        }
    }

    return new ByteArrayInputStream(baos.toByteArray());
}

From source file:com.hj.blog.common.utils.SensitiveWordMonitor.java

private static Set<String> loadBadWord(File file) {
    Set<String> badWordSet = new HashSet<>();
    try {/*from ww  w. j  a  v a 2 s .  c  o  m*/
        LineIterator it = FileUtils.lineIterator(file);
        while (it.hasNext()) {
            String badWord = it.nextLine();
            badWordSet.add(badWord);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return badWordSet;
}

From source file:de.rnd7.kata.reversi.logic.ai.AIMatrix.java

public static AIMatrix fromResource(final String name) throws IOException {
    final AIMatrix matrix = new AIMatrix();

    try (InputStream input = AIMatrix.class.getResourceAsStream(name)) {
        final LineIterator iterator = IOUtils.lineIterator(input, CharEncoding.UTF_8);

        int lineNumber = 0;
        while (iterator.hasNext()) {
            processLine(matrix, lineNumber++, iterator.next());
        }//from   www  . jav  a  2  s .c o m
    }

    return matrix;
}

From source file:edu.harvard.med.screensaver.io.libraries.WellDeprecator.java

private static Set<WellKey> readWellsFromFile(CommandLineApplication app) throws IOException, ParseException {
    Set<WellKey> wellKeys = new HashSet<WellKey>();
    LineIterator lines = FileUtils.lineIterator(new File(app.getCommandLineOptionValue("f")), null);
    while (lines.hasNext()) {
        String line = lines.nextLine().trim();
        if (line.length() > 0) {
            try {
                wellKeys.add(new WellKey(line));
            } catch (Exception e) {
                throw new FatalParseException("invalid well key '" + line + "': " + e);
            }/*from w  w  w  . j  av a  2  s  .c o  m*/
        }
    }
    return wellKeys;
}

From source file:com.el.wordament.NodeLoader.java

public static Node init() throws IOException {
    LineIterator iterator = FileUtils.lineIterator(new File("src/main/resources/dict.txt"));

    Node root = new Node();
    root.setWord(false);/*from   www .  j  a  v a 2s.c o  m*/

    while (iterator.hasNext()) {
        String line = iterator.next().toLowerCase().trim();
        createNodes(line, root, 0).setWord(true);
    }

    return root;
}

From source file:com.meltmedia.cadmium.core.meta.MimeTypeConfigProcessor.java

static void addDefaultMimeTypes(Map<String, String> mimeTypeMap)
        throws IllegalArgumentException, UnsupportedEncodingException {
    InputStream in = null;//from   w  w  w .  j  av  a2 s .c o m
    try {
        in = MimeTypeConfigProcessor.class.getResourceAsStream("mime.types");
        if (in == null) {
            log.warn("The default mime type file is missing.");
            return;
        }
        LineIterator lineIterator = new LineIterator(new InputStreamReader(in, "UTF-8"));
        while (lineIterator.hasNext()) {
            String line = lineIterator.next();
            line = line.replaceAll("(\\A[^#]*)(#.*)?\\Z", "$1").trim(); // kill comments.
            if (line.length() == 0)
                continue; // skip blank lines.
            String[] parts = line.split("\\s+");
            if (parts.length < 2)
                continue; // skip lines with no extensions.
            String type = parts[0];
            for (int i = 1; i < parts.length; i++) {
                mimeTypeMap.put(parts[i], type);
            }
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:net.femtoparsec.jwhois.utils.ByteUtils.java

/**
 * Convert an array of bytes to an array of lines
 * @param data the given array of bytes//from  w  w w . j  a v  a  2 s. co  m
 * @return an array of string
 */
public static String[] bytesToStrings(byte[] data) {
    if (data == null) {
        return null;
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
    LineIterator lineIterator = IOUtils.lineIterator(new InputStreamReader(inputStream));

    List<String> lines = new LinkedList<String>();
    while (lineIterator.hasNext()) {
        lines.add(lineIterator.nextLine());
    }

    return lines.toArray(new String[lines.size()]);
}

From source file:net.mindengine.blogix.tests.RequestSampleParser.java

public static List<Pair<String, String>> loadRequestChecksFromFile(File file) throws IOException {
    List<Pair<String, String>> samples = new LinkedList<Pair<String, String>>();
    LineIterator it = FileUtils.lineIterator(file, "UTF-8");

    RequestSampleParser parser = new RequestSampleParser(samples, it);
    while (it.hasNext()) {
        parser = parser.process(it.nextLine());
    }//from   w w  w .  j av a2 s  .  c  om
    parser.done();

    return samples;
}