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

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

Introduction

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

Prototype

public String nextLine() 

Source Link

Document

Returns the next line in the wrapped Reader.

Usage

From source file:com.okmich.hackerday.client.tool.ClientSimulator.java

@Override
public void run() {
    //read file content
    LineIterator lIt;
    try {//w  w w .j av  a2  s . c  o  m
        LOG.log(Level.INFO, "Reading the content of file");
        lIt = FileUtils.lineIterator(this.file);
    } catch (IOException ex) {
        Logger.getLogger(ClientSimulator.class.getName()).log(Level.SEVERE, null, ex);
        throw new RuntimeException(ex);
    }
    String line;
    LOG.log(Level.INFO, "Sending file content to kafka topic - {0}", this.topic);
    while (lIt.hasNext()) {
        line = lIt.nextLine();
        //send message to kafka
        this.kafkaMessageProducer.send(this.topic, line);
        try {
            Thread.currentThread().sleep(this.random.nextInt(1000));
        } catch (InterruptedException ex) {
            Logger.getLogger(ClientSimulator.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.ipcglobal.fredimport.process.Reference.java

/**
 * Creates the ref institutions.//from  ww  w  .jav  a  2 s.  com
 *
 * @param path the path
 * @throws Exception the exception
 */
private void createRefInstitutions(String path) throws Exception {
    refInstitutions = new HashMap<String, Object>();

    LineIterator it = FileUtils.lineIterator(new File(path + FILENAME_INSTITUTIONS), "UTF-8");
    try {
        while (it.hasNext()) {
            // Format: <institution>
            String institution = it.nextLine().trim();
            refWorldRegions.put(institution, null);
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
}

From source file:com.ipcglobal.fredimport.process.Reference.java

/**
 * Creates the ref world regions./* w  w  w .  ja va2  s .c o  m*/
 *
 * @param path the path
 * @throws Exception the exception
 */
private void createRefWorldRegions(String path) throws Exception {
    refWorldRegions = new HashMap<String, Object>();

    LineIterator it = FileUtils.lineIterator(new File(path + FILENAME_WORLD_REGIONS), "UTF-8");
    try {
        while (it.hasNext()) {
            // Format: <worldRegion>
            String worldRegion = it.nextLine().trim();
            refWorldRegions.put(worldRegion, null);
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
}

From source file:com.ipcglobal.fredimport.process.Reference.java

/**
 * Creates the ref us cities states.//from   w w  w  .j  a v a  2s.co  m
 *
 * @param path the path
 * @throws Exception the exception
 */
private void createRefUSCitiesStates(String path) throws Exception {
    refCitiesByStates = new HashMap<String, String>();

    LineIterator it = FileUtils.lineIterator(new File(path + FILENAME_US_CITIES_STATES), "UTF-8");
    try {
        while (it.hasNext()) {
            // Format: <cities>|<AA-BB-CC>
            String line = it.nextLine();
            String[] fields = line.split("[|]");
            fields[0] = fields[0].trim();
            fields[1] = fields[1].trim();
            refCitiesByStates.put(fields[1], fields[0]);
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
}

From source file:fr.ericlab.mabed.structure.Corpus.java

public void prepareCorpus() {
    System.out.println(Util.getDate() + " Preparing corpus...");
    String[] fileArray = new File("input/").list();
    nbTimeSlices = 0;/*from   ww w  . j  a v  a2s .c o  m*/
    NumberFormat formatter = new DecimalFormat("00000000");
    ArrayList<Integer> list = new ArrayList<>();
    for (String filename : fileArray) {
        if (filename.endsWith(".text")) {
            try {
                list.add(formatter.parse(filename.substring(0, 8)).intValue());
            } catch (ParseException ex) {
                Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
            }
            nbTimeSlices++;
        }
    }
    int a = Collections.min(list), b = Collections.max(list);
    LineIterator it = null;
    try {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
        it = FileUtils.lineIterator(new File("input/" + formatter.format(a) + ".time"), "UTF-8");
        if (it.hasNext()) {
            Date parsedDate = dateFormat.parse(it.nextLine());
            startTimestamp = new java.sql.Timestamp(parsedDate.getTime());
        }
        it = FileUtils.lineIterator(new File("input/" + formatter.format(b) + ".time"), "UTF-8");
        String lastLine = "";
        while (it.hasNext()) {
            lastLine = it.nextLine();
        }
        Date parsedDate = dateFormat.parse(lastLine);
        endTimestamp = new java.sql.Timestamp(parsedDate.getTime());
    } catch (IOException | ParseException ex) {
        Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        LineIterator.closeQuietly(it);
    }
    System.out.print("   - Computing word frequencies");
    GlobalIndexer indexer = new GlobalIndexer(configuration.numberOfThreads, false);
    try {
        indexer.index("input/", configuration.stopwords);
    } catch (InterruptedException | IOException ex) {
        Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
    }
    indexer = new GlobalIndexer(configuration.numberOfThreads, true);
    try {
        indexer.index("input/", configuration.stopwords);
    } catch (InterruptedException | IOException ex) {
        Logger.getLogger(Corpus.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println(", 100% done.");
}

From source file:com.ipcglobal.fredimport.process.Reference.java

/**
 * Creates the ref us states./*from ww w. j av  a2  s .c o  m*/
 *
 * @param path the path
 * @throws Exception the exception
 */
private void createRefUSStates(String path) throws Exception {
    refStateAbbrevsByNames = new HashMap<String, String>();
    refValidStateAbbrevs = new HashMap<String, Object>();

    LineIterator it = FileUtils.lineIterator(new File(path + FILENAME_US_STATE_NAMES_ABBREVS), "UTF-8");
    try {
        while (it.hasNext()) {
            // Format: <stateName>|<stateAbbrev>
            String line = it.nextLine();
            String[] fields = line.split("[|]");
            fields[0] = fields[0].trim();
            fields[1] = fields[1].trim();
            refStateAbbrevsByNames.put(fields[0], fields[1]);
            refValidStateAbbrevs.put(fields[1], null);
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
}

From source file:com.seniorproject.semanticweb.services.WebServices.java

public ArrayList<String> replaceWithPrefix(String filepath) throws IOException {
    File file = new File(filepath);
    LineIterator it = FileUtils.lineIterator(file, "UTF-8");
    ArrayList<String> results = new ArrayList<>();
    try {/* w  ww. j a v a 2s.  c o m*/
        while (it.hasNext()) {
            String content = it.nextLine();
            content = content.replace("^^<http://www.w3.org/2001/XMLSchema#int>", "");
            content = content.replace("<http://xmlns.com/foaf/0.1/page>\n", "");
            content = content.replace("<http://www.w3.org/2002/07/owl#sameAs>\n", "");
            content = content.replace("<http://www.w3.org/2000/01/rdf-schema#label>\n", "");
            content = content.replace("<http://dbpedia.org/property/hasPhotoCollection>\n", "");
            content = content.replace("<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>\n", "");
            content = content.replace("<http://www.w3.org/2002/07/owl#", "owl:");
            content = content.replace("<http://www.w3.org/2001/XMLSchema#", "xsd:");
            content = content.replace("<http://www.w3.org/2000/01/rdf-schema#", "rdfs:");
            content = content.replace("<http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:");
            content = content.replace("<http://xmlns.com/foaf/0.1/", "foaf:");
            content = content.replace("<http://data.linkedmdb.org/resource/oddlinker/", "oddlinker:");
            content = content.replace("<file:/C:/d2r-server-0.4/mapping.n3#", "map:");
            content = content.replace("<http://data.linkedmdb.org/resource/movie/", "movie:");
            content = content.replace("<http://data.linkedmdb.org/resource/", "db:");
            content = content.replace("<http://dbpedia.org/property/", "dbpedia:");
            content = content.replace("<http://www.w3.org/2004/02/skos/core#", "skos:");
            content = content.replace("<http://purl.org/dc/terms/", "dc:");
            content = content.replace(">", "");
            content = content.replace("<", "");
            results.add(content);
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
    return results;
}

From source file:com.nts.alphamale.monitor.EventMonitor.java

/**
 * "adb [-s serial] shell getevent -lt" ? ? ?  ?.
 * @see <a  href="https://source.android.com/devices/input/getevent.html">Getevent</a>
 * @param li//from   w w  w. ja v  a  2 s.c  o  m
 * @throws InterruptedException 
 */
public void eventLogAnalysis(LineIterator li) throws Exception {
    boolean tracking = false;
    int multiCount = 0;
    List<EventLog> evtLogList = new ArrayList<EventLog>();
    Map<Integer, List<Point>> multiSlot = new HashMap<Integer, List<Point>>();
    while (li.hasNext()) {
        String readLine = li.nextLine().trim();
        Matcher m = p.matcher(readLine);
        if (m.find()) {
            EventLog event = new EventLog(m);
            if (readLine.contains("EV_KEY")) {
                makeKeyEvent(event);
                evtLogList.clear();
            }
            if (event.getAbsLabel().equals("ABS_MT_TRACKING_ID") && event.getAbsValue() != Integer.MAX_VALUE) {
                if (!multiSlot.containsKey(multiCount))
                    multiSlot.put(multiCount, new ArrayList<Point>());
                multiCount++;
                tracking = true;

            }
            if (event.getAbsLabel().equals("ABS_MT_TRACKING_ID") && event.getAbsValue() == Integer.MAX_VALUE) {
                multiCount--;
                if (multiCount == 0) {
                    tracking = false;
                    if (!evtLogList.isEmpty()) {
                        makeMultiTrackingEvent(multiSlot, evtLogList);
                    }
                }
            }

            if (tracking == true) {
                if (event.getAbsLabel().contains("ABS_MT_POSITION")
                        || event.getAbsLabel().contains("ABS_MT_SLOT"))
                    evtLogList.add(event);
            }
        }
    }
}

From source file:com.ipcglobal.fredimport.process.Reference.java

/**
 * Creates the ref sexes./*from   ww  w  . j a v  a  2s.  co m*/
 *
 * @param path the path
 * @throws Exception the exception
 */
private void createRefSexes(String path) throws Exception {
    refSexes = new HashMap<String, String>();

    LineIterator it = FileUtils.lineIterator(new File(path + FILENAME_SEXES), "UTF-8");
    try {
        while (it.hasNext()) {
            // Format: <identifier>|<M|F|A>
            // Example: All Persons|A
            String line = it.nextLine();
            String[] fields = line.split("[|]");
            refSexes.put(fields[0].trim(), fields[1].trim());
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
}

From source file:edu.cornell.med.icb.goby.reads.PicardFastaIndexedSequence.java

public PicardFastaIndexedSequence(final String filename) throws FileNotFoundException {
    delegate = new IndexedFastaSequenceFile(new File(filename));
    indexDelegate = new FastaSequenceIndex(new File(filename + ".fai"));
    final int numContigs = indexDelegate.size();
    if (!delegate.isIndexed())
        throw new FileNotFoundException("An fasta idx index must be found for filename " + filename);

    lengths = new int[numContigs];
    names = new String[numContigs];
    basesPerLine = new long[numContigs];

    final LineIterator lineIt = new LineIterator(new FileReader(filename + ".fai"));

    // collect the contig names by parsing the text fai file. For some bizarre reason neither the
    // IndexedFastaSequenceFile class nor the FastaSequenceIndex class expose the contig names, yet
    // contig name is the parameter expected to get data from the sequences!
    int index = 0;
    while (lineIt.hasNext()) {
        final String line = lineIt.nextLine();
        final String[] tokens = line.split("[\\s]");
        names[index] = tokens[0];/*ww w . j  a  v  a 2 s  . c  o  m*/
        namesToIndices.put(tokens[0], index);
        lengths[index] = Integer.parseInt(tokens[1]);
        basesPerLine[index] = Long.parseLong(tokens[2]);
        index++;
    }

}