Beispiel #1
0
  private void updateColumnNames(ControlFile file) throws IOException {
    boolean hasHeaderRow = file.getFileTypeControl().hasHeaderRow;
    CSVReader headerReader = getCSVReader(file, 0);
    String[] row = headerReader.readNext();

    if (hasHeaderRow) {
      columnNames = row;
    } else {
      columnNames = generatePlaceholderNames(row.length);
    }
    fireTableStructureChanged();
  }
Beispiel #2
0
  private CSVReader getCSVReader(ControlFile controlFile, int skip) throws IOException {
    String path = controlFile.getFileTypeControl().filePath;
    String encoding = controlFile.getFileTypeControl().encoding;
    char sep = controlFile.getFileTypeControl().separator.charAt(0);
    char quote = controlFile.getFileTypeControl().quote.charAt(0);
    char escape = '\u0000';

    InputStreamReader inputReader =
        new InputStreamReader(
            new FileInputStream(controlFile.getFileTypeControl().filePath),
            controlFile.getFileTypeControl().encoding);

    if (controlFile.getFileTypeControl().escape != null) {
      if (controlFile.getFileTypeControl().escape.equals("")) escape = '\u0000';
      else escape = controlFile.getFileTypeControl().escape.charAt(0);
    }
    CSVReader reader = new CSVReader(inputReader, sep, quote, escape, skip);

    return reader;
  }
Beispiel #3
0
  // Return rows added
  private int addSamples(ControlFile controlFile) throws IOException {
    CSVReader reader = getCSVReader(controlFile, controlFile.getFileTypeControl().skip);
    String[] row = reader.readNext();

    int rowsAdded = 0;
    while (row != null && rowsAdded < rowsToSample) {
      // The consumers of this class assume a table with an equal number of columns in every row.
      // If the row is blank, we'll need to get a placeholder with as many columns as the others to
      // allow the
      // control file editor the ability to load.
      if (isBlankRow(row)) {
        insertData(getBlankPlaceholderRow(getColumnCount()));
      } else {
        insertData(row);
      }
      rowsAdded++;
      row = reader.readNext();
    }

    return rowsAdded;
  }