Android Open Source - DIYgenomics_Android C S V Parser






From Project

Back to project page DIYgenomics_Android.

License

The source code is released under:

/** * Copyright (C) 2010 DIYgenomics diygenomics.org * Copyright (C) 2010 Melanie Swan mxswan@gmail * Copyright (C) 2010 Michael Kolb * Copyright (C) 2010 Lawrence S. Wong * All rights reserved. * * M...

If you think the Android project DIYgenomics_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.diygenomics.pg.utils;
/*from  www . java2 s .co  m*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

import org.diygenomics.pg.utils.Row;


public class CSVParser {
  
  static final String TAG = "CSVParser";
  
  private CSVParser() {
  };
  
  
  public static ArrayList<Row> parse(InputStream in, boolean hasHeader) {
    MLog.enable(TAG);
    ArrayList<Row> lines = new ArrayList<Row>();
    BufferedReader reader  = new BufferedReader(new InputStreamReader(in),1024);
    String line = null;
    try {
      if (hasHeader) {
        // read off first line with table headers
        line = reader.readLine();
      }
      String del = ",";
      int ix = 0;
      while ((line = reader.readLine()) != null) {
        Row row = new Row(); 
        StringTokenizer st = new StringTokenizer(line,del, true);
        boolean lastWasDelimiter = false;
        while (st.hasMoreTokens()) {
          String tok = st.nextToken();
          
          if (tok.equals(del)) {
            if (lastWasDelimiter) {
              row.add("");
            }
            lastWasDelimiter = true;
          } else {
            row.add(tok);
            lastWasDelimiter = false;
          }
        }
        if (lastWasDelimiter) {
          // compensate for missing last element
          row.add("");
        }
        lines.add(row);
        ix++;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    return lines;
  }

  
  
}




Java Source Code List

android.widget.BasicExpandableList.java
android.widget.BasicListView.java
org.diygenomics.pg.CategoriesActivity.java
org.diygenomics.pg.CategoryItemActivity.java
org.diygenomics.pg.Category.java
org.diygenomics.pg.Constants.java
org.diygenomics.pg.Data.java
org.diygenomics.pg.DotUtils.java
org.diygenomics.pg.Genome.java
org.diygenomics.pg.ImportActivity.java
org.diygenomics.pg.InfoHandler.java
org.diygenomics.pg.Main.java
org.diygenomics.pg.MappingItem.java
org.diygenomics.pg.StudiesActivity.java
org.diygenomics.pg.Study.java
org.diygenomics.pg.Variant.java
org.diygenomics.pg.utils.CSVParser.java
org.diygenomics.pg.utils.ConditionVariantTableRowComparator.java
org.diygenomics.pg.utils.Flurry.java
org.diygenomics.pg.utils.MLog.java
org.diygenomics.pg.utils.Row.java