コード例 #1
0
ファイル: CSVFileReader.java プロジェクト: cryptedp/WaDosUtil
  /**
   * reads and parses a csv file
   *
   * @param reader
   * @throws IOException
   */
  protected CSVFileReader(BufferedReader reader) throws IOException {
    String line;
    String attributeLine = reader.readLine();
    HashMap<String, Integer> candidates = getSeparationCandidates(attributeLine);
    ArrayList<String> allLines = new ArrayList<>();
    while ((line = reader.readLine()) != null) {
      allLines.add(line);
    }
    removeSeparationCandidates(candidates, allLines);
    this.separation = getSeparationCharacter(candidates);

    this.attributes = CSVFile.decodeForValue(attributeLine.split(this.separation, -1));
    this.entities = new String[allLines.size()][];
    int index = 0;
    for (String entity : allLines) {
      this.entities[index] = CSVFile.decodeForValue(entity.split(this.separation, -1));
      index++;
    }
    if (!muted) {
      System.out.println("Separation character = " + this.separation);
      System.out.println("Number of entities = " + allLines.size());
      System.out.println("Number of attributes = " + this.attributes.length);
    }
  }