Java Code Examples for org.apache.commons.csv.CSVFormat#TDF

The following examples show how to use org.apache.commons.csv.CSVFormat#TDF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSVUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static CSVFormat createCSVFormat(final PropertyContext context, final Map<String, String> variables) {
    final String formatName = context.getProperty(CSV_FORMAT).getValue();
    if (formatName.equalsIgnoreCase(CUSTOM.getValue())) {
        return buildCustomFormat(context, variables);
    }
    if (formatName.equalsIgnoreCase(RFC_4180.getValue())) {
        return CSVFormat.RFC4180;
    } else if (formatName.equalsIgnoreCase(EXCEL.getValue())) {
        return CSVFormat.EXCEL;
    } else if (formatName.equalsIgnoreCase(TDF.getValue())) {
        return CSVFormat.TDF;
    } else if (formatName.equalsIgnoreCase(MYSQL.getValue())) {
        return CSVFormat.MYSQL;
    } else if (formatName.equalsIgnoreCase(INFORMIX_UNLOAD.getValue())) {
        return CSVFormat.INFORMIX_UNLOAD;
    } else if (formatName.equalsIgnoreCase(INFORMIX_UNLOAD_CSV.getValue())) {
        return CSVFormat.INFORMIX_UNLOAD_CSV;
    } else {
        return CSVFormat.DEFAULT;
    }
}
 
Example 2
Source File: DebateHTMLParser.java    From argument-reasoning-comprehension-task with Apache License 2.0 5 votes vote down vote up
public DebateHTMLParser()
        throws IOException
{
    urlStances = new HashMap<>();

    InputStream inputStream = this.getClass().getClassLoader()
            .getResourceAsStream("rfd-controversies/rfd-manual-cleaning-controversies.tsv");

    CSVParser parser = new CSVParser(new InputStreamReader(inputStream), CSVFormat.TDF);
    for (CSVRecord csvRecord : parser) {
        boolean keepRFDDebate = "".equals(csvRecord.get(0));

        if (keepRFDDebate) {
            String url = csvRecord.get(5);

            SortedSet<String> stances = new TreeSet<>();
            // yes/no stance?
            if ("y".equals(csvRecord.get(3))) {
                stances.addAll(Arrays.asList("Yes", "No"));
            }
            else {
                stances.addAll(Arrays.asList(csvRecord.get(3), csvRecord.get(4)));
            }

            if (stances.size() != 2) {
                throw new IllegalStateException(
                        "Expected 2 stances but got " + stances + "; " + csvRecord.get(1));
            }

            urlStances.put(url, stances);
        }
    }
}
 
Example 3
Source File: ReadCsv.java    From opentest with MIT License 4 votes vote down vote up
/**
 * Returns a CSVFormat object given the CSV format as a string.
 *
 * @param format
 * @return
 */
private CSVFormat getCsvFormat(String format) {
    CSVFormat csvFormat = null;

    switch (format.trim().toLowerCase()) {
        case "default":
            csvFormat = CSVFormat.DEFAULT;
            break;
        case "excel":
            csvFormat = CSVFormat.EXCEL;
            break;
        case "informixunload":
        case "informix-unload":
        case "informix_unload":
            csvFormat = CSVFormat.INFORMIX_UNLOAD;
            break;
        case "informixunloadcsv":
        case "informix-unload-csv":
        case "informix_unload_csv":
            csvFormat = CSVFormat.INFORMIX_UNLOAD_CSV;
            break;
        case "mysql":
            csvFormat = CSVFormat.MYSQL;
            break;
        case "postgres":
        case "postgresql-csv":
        case "postgresql_csv":
            csvFormat = CSVFormat.POSTGRESQL_CSV;
            break;
        case "postgresql-text":
        case "postgresql_text":
            csvFormat = CSVFormat.POSTGRESQL_TEXT;
            break;
        case "rfc4180":
            csvFormat = CSVFormat.RFC4180;
        case "tdf":
            csvFormat = CSVFormat.TDF;
        default:
            throw new RuntimeException(String.format("CSV format \"%s\" is not among the supported formats"));
    }

    return csvFormat;
}
 
Example 4
Source File: TsvWriter.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@Override
CSVPrinter getCsvPrinter(Writer writer) throws IOException {
  return new CSVPrinter(writer, CSVFormat.TDF);
}
 
Example 5
Source File: TSVWriter.java    From tabula-java with MIT License 4 votes vote down vote up
public TSVWriter() {
	super(CSVFormat.TDF);
}
 
Example 6
Source File: CSVRecordReader.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public void init(File dataFile, Set<String> fieldsToRead, @Nullable RecordReaderConfig recordReaderConfig)
    throws IOException {
  _dataFile = dataFile;
  CSVRecordReaderConfig config = (CSVRecordReaderConfig) recordReaderConfig;
  char multiValueDelimiter;
  if (config == null) {
    _format = CSVFormat.DEFAULT.withDelimiter(CSVRecordReaderConfig.DEFAULT_DELIMITER).withHeader();
    multiValueDelimiter = CSVRecordReaderConfig.DEFAULT_MULTI_VALUE_DELIMITER;
  } else {
    CSVFormat format;
    String formatString = config.getFileFormat();
    if (formatString == null) {
      format = CSVFormat.DEFAULT;
    } else {
      switch (formatString.toUpperCase()) {
        case "EXCEL":
          format = CSVFormat.EXCEL;
          break;
        case "MYSQL":
          format = CSVFormat.MYSQL;
          break;
        case "RFC4180":
          format = CSVFormat.RFC4180;
          break;
        case "TDF":
          format = CSVFormat.TDF;
          break;
        default:
          format = CSVFormat.DEFAULT;
          break;
      }
    }
    char delimiter = config.getDelimiter();
    format = format.withDelimiter(delimiter);
    String csvHeader = config.getHeader();
    if (csvHeader == null) {
      format = format.withHeader();
    } else {
      format = format.withHeader(StringUtils.split(csvHeader, delimiter));
    }
    _format = format;
    multiValueDelimiter = config.getMultiValueDelimiter();
  }
  _recordExtractor = new CSVRecordExtractor();
  CSVRecordExtractorConfig recordExtractorConfig = new CSVRecordExtractorConfig();
  recordExtractorConfig.setMultiValueDelimiter(multiValueDelimiter);
  _recordExtractor.init(fieldsToRead, recordExtractorConfig);
  init();
}