Java 类org.apache.commons.csv.QuoteMode 实例源码

项目:cikm16-wdvd-feature-extraction    文件:ActionStatisticsProcessor.java   
private void logResults() {
    logger.info("Action frequency distribution:\n" + FrequencyUtils.formatFrequency(actionDistribution));
    logger.info("Action frequency distribution of rollback-reverted revisions:\n" + FrequencyUtils.formatFrequency(rollbackRevertedActionDistribution));
    logger.info("Action frequency distribution of non-rollback-reverted revisions:\n" + FrequencyUtils.formatFrequency(nonRollbackRevertedActionDistribution));

    try {
        Writer writer = new PrintWriter(path, "UTF-8");
        CSVPrinter csvWriter = CSVFormat.RFC4180.withQuoteMode(QuoteMode.ALL)
                .withHeader("month", "action", "count").print(writer);

        for (Entry<String, HashMap<String, Integer>> entry: getSortedList(monthlyActionDistribution)) {
            String month = entry.getKey();

            for (Entry<String, Integer> entry2: getSortedList2(entry.getValue())) {
                String action = entry2.getKey();
                Integer value = entry2.getValue();

                csvWriter.printRecord(month, action, value);
            }
        }
        csvWriter.close();
    } catch (IOException e) {
        logger.error("", e);
    }
}
项目:StageFever    文件:SongAdapter.java   
/**
 * Import model data from CSV file
 *
 * @param inStr
 *          input stream of CSV file
 * @param fieldDelimiter
 *          delimiter sequence between data items
 */
public void importFromCsvFile(InputStream inStr, String fieldDelimiter)
{
    BufferedReader rdr;
    // clear song list
    clear();
    try
    {
        rdr = new BufferedReader(new InputStreamReader(inStr));
        for(CSVRecord record : CSVFormat.newFormat(fieldDelimiter.charAt(0))
                                           .withQuote('"')
                                           .withQuoteMode(QuoteMode.MINIMAL).parse(rdr))
        {
            add(new Song(record));
        }
        rdr.close();
    } catch (IOException e)
    {
        e.printStackTrace();
    }
}
项目:cascading.csv    文件:CsvInputFormat.java   
/**
 * Creates a CSV format from a Hadoop configuration.
 */
private static CSVFormat createFormat(Configuration conf) {
  CSVFormat format = CSVFormat.newFormat(conf.get(CSV_READER_DELIMITER, DEFAULT_CSV_READER_DELIMITER).charAt(0))
    .withSkipHeaderRecord(conf.getBoolean(CSV_READER_SKIP_HEADER, DEFAULT_CSV_READER_SKIP_HEADER))
    .withRecordSeparator(conf.get(CSV_READER_RECORD_SEPARATOR, DEFAULT_CSV_READER_RECORD_SEPARATOR))
    .withIgnoreEmptyLines(conf.getBoolean(CSV_READER_IGNORE_EMPTY_LINES, DEFAULT_CSV_READER_IGNORE_EMPTY_LINES))
    .withIgnoreSurroundingSpaces(conf.getBoolean(CSV_READER_IGNORE_SURROUNDING_SPACES, DEFAULT_CSV_READER_IGNORE_SURROUNDING_SPACES))
    .withNullString(conf.get(CSV_READER_NULL_STRING, DEFAULT_CSV_READER_NULL_STRING));

  String[] header = conf.getStrings(CSV_READER_COLUMNS);
  if (header != null && header.length > 0)
    format = format.withHeader(header);

  String escape = conf.get(CSV_READER_ESCAPE_CHARACTER, DEFAULT_CSV_READER_ESCAPE_CHARACTER);
  if (escape != null)
    format = format.withEscape(escape.charAt(0));

  String quote = conf.get(CSV_READER_QUOTE_CHARACTER, DEFAULT_CSV_READER_QUOTE_CHARACTER);
  if (quote != null)
    format = format.withQuote(quote.charAt(0));

  String quoteMode = conf.get(CSV_READER_QUOTE_MODE, DEFAULT_CSV_READER_QUOTE_MODE);
  if (quoteMode != null)
    format = format.withQuoteMode(QuoteMode.valueOf(quoteMode));
  return format;
}
项目:cascading.csv    文件:CsvOutputFormat.java   
/**
 * Creates a CSV format from a Hadoop configuration.
 */
private static CSVFormat createFormat(Configuration conf) {
  CSVFormat format = CSVFormat.newFormat(conf.get(CSV_WRITER_DELIMITER, DEFAULT_CSV_WRITER_DELIMITER).charAt(0))
    .withSkipHeaderRecord(conf.getBoolean(CSV_WRITER_SKIP_HEADER, DEFAULT_CSV_WRITER_SKIP_HEADER))
    .withRecordSeparator(conf.get(CSV_WRITER_RECORD_SEPARATOR, DEFAULT_CSV_WRITER_RECORD_SEPARATOR))
    .withIgnoreEmptyLines(conf.getBoolean(CSV_WRITER_IGNORE_EMPTY_LINES, DEFAULT_CSV_WRITER_IGNORE_EMPTY_LINES))
    .withIgnoreSurroundingSpaces(conf.getBoolean(CSV_WRITER_IGNORE_SURROUNDING_SPACES, DEFAULT_CSV_WRITER_IGNORE_SURROUNDING_SPACES))
    .withNullString(conf.get(CSV_WRITER_NULL_STRING, DEFAULT_CSV_WRITER_NULL_STRING));

  String[] header = conf.getStrings(CSV_WRITER_COLUMNS);
  if (header != null && header.length > 0)
    format = format.withHeader(header);

  String escape = conf.get(CSV_WRITER_ESCAPE_CHARACTER, DEFAULT_CSV_WRITER_ESCAPE_CHARACTER);
  if (escape != null)
    format = format.withEscape(escape.charAt(0));

  String quote = conf.get(CSV_WRITER_QUOTE_CHARACTER, DEFAULT_CSV_WRITER_QUOTE_CHARACTER);
  if (quote != null)
    format = format.withQuote(quote.charAt(0));

  String quoteMode = conf.get(CSV_WRITER_QUOTE_MODE, DEFAULT_CSV_WRITER_QUOTE_MODE);
  if (quoteMode != null)
    format = format.withQuoteMode(QuoteMode.valueOf(quoteMode));
  return format;
}
项目:flow    文件:CsvFormats.java   
@Nullable
private static QuoteMode getQuoteMode(@Nonnull Config config, @Nonnull String key) {
    switch (config.getString(key, "default")) {
        case "default":
            return null;
        case "all":
            return QuoteMode.ALL;
        case "minimal":
            return QuoteMode.MINIMAL;
        case "non_numeric":
            return QuoteMode.NON_NUMERIC;
        case "none":
            return QuoteMode.NONE;
        default:
            return null;
    }
}
项目:commons-csv    文件:JiraCsv213Test.java   
private void createEndChannel(final File csvFile) {
    // @formatter:off
    final CSVFormat csvFormat =
            CSVFormat.DEFAULT
                .withDelimiter(';')
                .withFirstRecordAsHeader()
                .withRecordSeparator('\n')
                .withQuoteMode(QuoteMode.ALL);
    // @formatter:on
    try (CSVParser parser = csvFormat
            .parse(new InputStreamReader(new FileInputStream(csvFile), StandardCharsets.UTF_8))) {
        if (parser.iterator().hasNext()) {
            System.out.println(parser.getCurrentLineNumber());
            System.out.println(parser.getRecordNumber());
            // get only first record we don't need other's
            final CSVRecord firstRecord = parser.iterator().next(); // this fails

            return;
        }
    } catch (final IOException e) {
        throw new RuntimeException("Error while adding end channel to csv", e);
    }

    return;
}
项目:logging-log4j2    文件:AbstractCsvLayout.java   
protected static CSVFormat createFormat(final String format, final Character delimiter, final Character escape,
        final Character quote, final QuoteMode quoteMode, final String nullString, final String recordSeparator) {
    CSVFormat csvFormat = CSVFormat.valueOf(format);
    if (isNotNul(delimiter)) {
        csvFormat = csvFormat.withDelimiter(delimiter);
    }
    if (isNotNul(escape)) {
        csvFormat = csvFormat.withEscape(escape);
    }
    if (isNotNul(quote)) {
        csvFormat = csvFormat.withQuote(quote);
    }
    if (quoteMode != null) {
        csvFormat = csvFormat.withQuoteMode(quoteMode);
    }
    if (nullString != null) {
        csvFormat = csvFormat.withNullString(nullString);
    }
    if (recordSeparator != null) {
        csvFormat = csvFormat.withRecordSeparator(recordSeparator);
    }
    return csvFormat;
}
项目:logging-log4j2    文件:CsvParameterLayout.java   
@PluginFactory
public static AbstractCsvLayout createLayout(
        // @formatter:off
        @PluginConfiguration final Configuration config,
        @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
        @PluginAttribute("delimiter") final Character delimiter,
        @PluginAttribute("escape") final Character escape,
        @PluginAttribute("quote") final Character quote,
        @PluginAttribute("quoteMode") final QuoteMode quoteMode,
        @PluginAttribute("nullString") final String nullString,
        @PluginAttribute("recordSeparator") final String recordSeparator,
        @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
        @PluginAttribute("header") final String header, 
        @PluginAttribute("footer") final String footer)
        // @formatter:on
{

    final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
    return new CsvParameterLayout(config, charset, csvFormat, header, footer);
}
项目:logging-log4j2    文件:CsvLogEventLayout.java   
@PluginFactory
public static CsvLogEventLayout createLayout(
        // @formatter:off
        @PluginConfiguration final Configuration config,
        @PluginAttribute(value = "format", defaultString = DEFAULT_FORMAT) final String format,
        @PluginAttribute("delimiter") final Character delimiter,
        @PluginAttribute("escape") final Character escape,
        @PluginAttribute("quote") final Character quote,
        @PluginAttribute("quoteMode") final QuoteMode quoteMode,
        @PluginAttribute("nullString") final String nullString,
        @PluginAttribute("recordSeparator") final String recordSeparator,
        @PluginAttribute(value = "charset", defaultString = DEFAULT_CHARSET) final Charset charset,
        @PluginAttribute("header") final String header,
        @PluginAttribute("footer") final String footer)
        // @formatter:on
{

    final CSVFormat csvFormat = createFormat(format, delimiter, escape, quote, quoteMode, nullString, recordSeparator);
    return new CsvLogEventLayout(config, charset, csvFormat, header, footer);
}
项目:oryx2    文件:TextUtils.java   
/**
 * @param elements numbers to join by space to make one line of text
 * @return one line of text, formatted according to PMML quoting rules
 */
public static String joinPMMLDelimitedNumbers(Iterable<? extends Number> elements) {
  // bit of a workaround because NON_NUMERIC quote mode still quote "-1"!
  CSVFormat format = formatForDelimiter(' ').withQuoteMode(QuoteMode.NONE);
  // No quoting, no need to convert quoting
  return doJoinDelimited(elements, format);
}
项目:careconnect-reference-implementation    文件:RITerminologyLoader.java   
public UploadStatistics processLoincFiles(List<byte[]> theZipBytes, RequestDetails theRequestDetails) {
    String url = LOINC_URL;
    final CodeSystemEntity codeSystemVersion = codeSvc.findBySystem(url);
    final Map<String, ConceptEntity> code2concept = new HashMap<String, ConceptEntity>();

    IRecordHandler handler = new LoincHandler(codeSystemVersion, code2concept);
    iterateOverZipFile(theZipBytes, LOINC_FILE, handler, ',', QuoteMode.NON_NUMERIC);

    handler = new LoincHierarchyHandler(codeSystemVersion, code2concept);
    iterateOverZipFile(theZipBytes, LOINC_HIERARCHY_FILE, handler, ',', QuoteMode.NON_NUMERIC);

    theZipBytes.clear();

    for (Iterator<Map.Entry<String, ConceptEntity>> iter = code2concept.entrySet().iterator(); iter.hasNext();) {
        Map.Entry<String, ConceptEntity> next = iter.next();
        // if (isBlank(next.getKey())) {
        // ourLog.info("Removing concept with blankc code[{}] and display [{}", next.getValue().getCode(), next.getValue().getDisplay());
        // iter.remove();
        // continue;
        // }
        ConceptEntity nextConcept = next.getValue();
        if (nextConcept.getParents().isEmpty()) {
            codeSystemVersion.getConcepts().add(nextConcept);
        }
    }

    ourLog.info("Have {} total concepts, {} root concepts", code2concept.size(), codeSystemVersion.getConcepts().size());


    storeCodeSystem(theRequestDetails, codeSystemVersion);

    return new UploadStatistics(code2concept.size());
}
项目:careconnect-reference-implementation    文件:TerminologyLoaderDao.java   
public UploadStatistics processLoincFiles(List<byte[]> theZipBytes, RequestDetails theRequestDetails) {
    String url = LOINC_URL;
    final CodeSystemEntity codeSystemVersion = codeSvc.findBySystem(url);
    final Map<String, ConceptEntity> code2concept = new HashMap<String, ConceptEntity>();

    IRecordHandler handler = new LoincHandler(codeSystemVersion, code2concept);
    iterateOverZipFile(theZipBytes, LOINC_FILE, handler, ',', QuoteMode.NON_NUMERIC);

    handler = new LoincHierarchyHandler(codeSystemVersion, code2concept);
    iterateOverZipFile(theZipBytes, LOINC_HIERARCHY_FILE, handler, ',', QuoteMode.NON_NUMERIC);

    theZipBytes.clear();

    for (Iterator<Map.Entry<String, ConceptEntity>> iter = code2concept.entrySet().iterator(); iter.hasNext();) {
        Map.Entry<String, ConceptEntity> next = iter.next();
        // if (isBlank(next.getKey())) {
        // ourLog.info("Removing concept with blankc code[{}] and display [{}", next.getValue().getCode(), next.getValue().getDisplay());
        // iter.remove();
        // continue;
        // }
        ConceptEntity nextConcept = next.getValue();
        if (nextConcept.getParents().isEmpty()) {
            codeSystemVersion.getConcepts().add(nextConcept);
        }
    }

    ourLog.info("Have {} total concepts, {} root concepts", code2concept.size(), codeSystemVersion.getConcepts().size());


    storeCodeSystem(theRequestDetails, codeSystemVersion);

    return new UploadStatistics(code2concept.size());
}
项目:otus-api    文件:CsvWriterService.java   
public CsvWriterService() {
    try {
        out = new ByteArrayOutputStream();
        csvFileFormat = CSVFormat.newFormat(DELIMITER).withRecordSeparator(RECORD_SEPARATOR).withQuote('\"').withQuoteMode(QuoteMode.MINIMAL);
        csvFilePrinter = new CSVPrinter(new PrintWriter(out), csvFileFormat);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:Camel    文件:CsvDataFormatTest.java   
@Test
public void shouldOverrideQuoteMode() {
    CsvDataFormat dataFormat = new CsvDataFormat()
            .setQuoteMode(QuoteMode.ALL);

    // Properly saved
    assertSame(CSVFormat.DEFAULT, dataFormat.getFormat());
    assertEquals(QuoteMode.ALL, dataFormat.getQuoteMode());

    // Properly used
    assertEquals(QuoteMode.ALL, dataFormat.getActiveFormat().getQuoteMode());
}
项目:commons-csv    文件:JiraCsv203Test.java   
@Test
public void testQuoteModeAll() throws Exception {
    final CSVFormat format = CSVFormat.EXCEL
            .withNullString("N/A")
            .withIgnoreSurroundingSpaces(true)
            .withQuoteMode(QuoteMode.ALL);

    final StringBuffer buffer = new StringBuffer();
    final CSVPrinter printer = new CSVPrinter(buffer, format);
    printer.printRecord(new Object[] { null, "Hello", null, "World" });

    Assert.assertEquals("\"N/A\",\"Hello\",\"N/A\",\"World\"\r\n", buffer.toString());
}
项目:commons-csv    文件:JiraCsv203Test.java   
@Test
public void testQuoteModeAllNonNull() throws Exception {
    final CSVFormat format = CSVFormat.EXCEL
            .withNullString("N/A")
            .withIgnoreSurroundingSpaces(true)
            .withQuoteMode(QuoteMode.ALL_NON_NULL);

    final StringBuffer buffer = new StringBuffer();
    final CSVPrinter printer = new CSVPrinter(buffer, format);
    printer.printRecord(new Object[] { null, "Hello", null, "World" });

    Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
}
项目:commons-csv    文件:JiraCsv203Test.java   
@Test
public void testQuoteModeMinimal() throws Exception {
    final CSVFormat format = CSVFormat.EXCEL
            .withNullString("N/A")
            .withIgnoreSurroundingSpaces(true)
            .withQuoteMode(QuoteMode.MINIMAL);

    final StringBuffer buffer = new StringBuffer();
    final CSVPrinter printer = new CSVPrinter(buffer, format);
    printer.printRecord(new Object[] { null, "Hello", null, "World" });

    Assert.assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString());
}
项目:commons-csv    文件:JiraCsv203Test.java   
@Test
public void testQuoteModeNonNumeric() throws Exception {
    final CSVFormat format = CSVFormat.EXCEL
            .withNullString("N/A")
            .withIgnoreSurroundingSpaces(true)
            .withQuoteMode(QuoteMode.NON_NUMERIC);

    final StringBuffer buffer = new StringBuffer();
    final CSVPrinter printer = new CSVPrinter(buffer, format);
    printer.printRecord(new Object[] { null, "Hello", null, "World" });

    Assert.assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString());
}
项目:commons-csv    文件:JiraCsv203Test.java   
@Test
public void testWithoutNullString() throws Exception {
    final CSVFormat format = CSVFormat.EXCEL
            //.withNullString("N/A")
            .withIgnoreSurroundingSpaces(true)
            .withQuoteMode(QuoteMode.ALL);

    final StringBuffer buffer = new StringBuffer();
    final CSVPrinter printer = new CSVPrinter(buffer, format);
    printer.printRecord(new Object[] { null, "Hello", null, "World" });

    Assert.assertEquals(",\"Hello\",,\"World\"\r\n", buffer.toString());
}
项目:commons-csv    文件:JiraCsv203Test.java   
@Test
public void testWithEmptyValues() throws Exception {
    final CSVFormat format = CSVFormat.EXCEL
            .withNullString("N/A")
            .withIgnoreSurroundingSpaces(true)
            .withQuoteMode(QuoteMode.ALL);

    final StringBuffer buffer = new StringBuffer();
    final CSVPrinter printer = new CSVPrinter(buffer, format);
    printer.printRecord(new Object[] { "", "Hello", "", "World" });
    //printer.printRecord(new Object[] { null, "Hello", null, "World" });

    Assert.assertEquals("\"\",\"Hello\",\"\",\"World\"\r\n", buffer.toString());
}
项目:obevo    文件:CsvStaticDataWriter.java   
public static void start(final AquaRevengArgs args, File workDir) {
    final DbEnvironment env = new DbEnvironment();
    env.setPlatform(args.getDbPlatform());
    env.setSystemDbPlatform(args.getDbPlatform());
    if (args.getJdbcUrl() != null) {
        env.setJdbcUrl(args.getJdbcUrl());
    } else {
        env.setDbHost(args.getDbHost());
        env.setDbPort(args.getDbPort());
        env.setDbServer(args.getDbServer());
    }
    if (args.getDriverClass() != null) {
        env.setDriverClassName(args.getDriverClass());
    }
    final PhysicalSchema physicalSchema = PhysicalSchema.parseFromString(args.getDbSchema());
    final Schema schema = new Schema(physicalSchema.getPhysicalName());  // use the physical name as the schema name for the reverse-engineering
    env.setSchemas(Sets.immutable.with(schema));

    Credential credential = credentialReader.getCredential(args.getUsername(), args.getPassword(), false, null, null,
            null);

    DbDeployerAppContext ctxt = env.getAppContextBuilder().setCredential(credential).setWorkDir(workDir).buildDbContext();
    final CsvStaticDataWriter mw = new CsvStaticDataWriter(ctxt.getSqlExecutor(),
            ctxt.getDbMetadataManager());

    final MutableList<String> dataTables;
    if (args.getTables() != null && args.getTables().length > 0) {
        dataTables = Lists.mutable.with(args.getTables());
    } else {
        dataTables = FileUtilsCobra.readLines(new File(args.getInputDir(), STATIC_DATA_TABLES_FILE_NAME));
    }

    for (String table : dataTables) {
        System.out.println("Working on table " + table + " at " + new Date());

        CSVFormat csvFormat = CsvReaderDataSource.getCsvFormat(env.getDataDelimiter(), env.getNullToken()).withQuoteMode(QuoteMode.NON_NUMERIC);
        mw.writeTable(env.getPlatform(), physicalSchema, table.trim(),
                new File(args.getOutputPath(), env.getPlatform().getChangeType(ChangeType.STATICDATA_STR).getDirectoryName()),
                args.getUpdateTimeColumns(), csvFormat);
    }
}
项目:careconnect-reference-implementation    文件:ODSUploader.java   
@Override
public void run(CommandLine theCommandLine) throws ParseException {
    String targetServer = theCommandLine.getOptionValue("t");
    if (isBlank(targetServer)) {
        throw new ParseException("No target server (-t) specified");
    } else if (targetServer.startsWith("http") == false) {
        throw new ParseException("Invalid target server specified, must begin with 'http'");
    }

    ctx = getSpecVersionContext(theCommandLine);
    String exclude = theCommandLine.getOptionValue("e");

    if (isNotBlank(exclude)) {
        for (String next : exclude.split(",")) {
            if (isNotBlank(next)) {
                IIdType id = ctx.getVersion().newIdType();
                id.setValue(next);
                myExcludes.add(id);
            }
        }
    }

    if (ctx.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
           client = ctx.newRestfulGenericClient(targetServer);

           IRecordHandler handler = null;

           System.out.println("National Health Service Trust");
           handler = new OrgHandler("930621000000104","National Health Service Trust");
           uploadODSStu3(handler, targetServer, ctx, ',', QuoteMode.NON_NUMERIC, "etr.zip", "etr.csv","https://digital.nhs.uk/media/352/etr/zip/etr");
           uploadOrganisation();

           System.out.println("Health Authority (CCG)");
           handler = new OrgHandler("394747008","Health Authority");
           uploadODSStu3(handler, targetServer, ctx, ',', QuoteMode.NON_NUMERIC, "eccg.zip", "eccg.csv", "https://digital.nhs.uk/media/354/eccg/zip/eccg");
           uploadOrganisation();

           System.out.println("General practice");
           handler = new OrgHandler("394745000","General practice");
           uploadODSStu3(handler, targetServer, ctx, ',', QuoteMode.NON_NUMERIC, "epraccur.zip", "epraccur.csv", "https://digital.nhs.uk/media/372/epraccur/zip/epraccur");
           uploadOrganisation();

           System.out.println("National Health Service Trust site");
           handler = new LocationHandler("930631000000102", "National Health Service Trust site");
           uploadODSStu3(handler, targetServer, ctx, ',', QuoteMode.NON_NUMERIC, "ets.zip", "ets.csv", "https://digital.nhs.uk/media/351/ets/zip/ets");
           uploadLocation();

           System.out.println("GP practice site");
           handler = new LocationHandler("394761003", "GP practice site");
           uploadODSStu3(handler, targetServer, ctx, ',', QuoteMode.NON_NUMERIC, "ebranchs.zip", "ebranchs.csv", "https://digital.nhs.uk/media/393/ebranchs/zip/ebranchs");
           uploadLocation();

           System.out.println("GP");
           handler = new PractitionerHandler();
           uploadODSStu3(handler, targetServer, ctx, ',', QuoteMode.NON_NUMERIC, "egpcur.zip", "egpcur.csv","https://digital.nhs.uk/media/370/egpcur/zip/egpcur");
           uploadPractitioner();

           System.out.println("Consultants");
           handler = new ConsultantHandler();
           uploadODSStu3(handler, targetServer, ctx, ',', QuoteMode.NON_NUMERIC, "econcur.zip", "econcur.csv","https://digital.nhs.uk/media/450/econcur/zip/econcur");
           uploadPractitioner();


    }

}
项目:greyfish    文件:DBSCANTest.java   
@Before
public void setUp() throws Exception {
    csvRecords = CSVParser.parse(Resources.getResource(DBSCANTest.class, "iris.csv"),
            Charset.defaultCharset(),
            CSVFormat.newFormat(',').withHeader().withQuote('"').withQuoteMode(QuoteMode.NON_NUMERIC));
}
项目:pippo    文件:CsvEngine.java   
public void setQuoteMode(QuoteMode quoteMode) {
    this.quoteMode = quoteMode;
}
项目:commons-csv    文件:JiraCsv167Test.java   
@Test
public void parse() throws IOException {
    int totcomment = 0;
    int totrecs = 0;
    try (final BufferedReader br = new BufferedReader(getTestInput())) {
        String s = null;
        boolean lastWasComment = false;
        while ((s = br.readLine()) != null) {
            if (s.startsWith("#")) {
                if (!lastWasComment) { // comments are merged
                    totcomment++;
                }
                lastWasComment = true;
            } else {
                totrecs++;
                lastWasComment = false;
            }
        }
    }
    CSVFormat format = CSVFormat.DEFAULT;
    //
    format = format.withAllowMissingColumnNames(false);
    format = format.withCommentMarker('#');
    format = format.withDelimiter(',');
    format = format.withEscape('\\');
    format = format.withHeader("author", "title", "publishDate");
    format = format.withHeaderComments("headerComment");
    format = format.withNullString("NULL");
    format = format.withIgnoreEmptyLines(true);
    format = format.withIgnoreSurroundingSpaces(true);
    format = format.withQuote('"');
    format = format.withQuoteMode(QuoteMode.ALL);
    format = format.withRecordSeparator('\n');
    format = format.withSkipHeaderRecord(false);
    //
    int comments = 0;
    int records = 0;
    try (final CSVParser parser = format.parse(getTestInput())) {
        for (final CSVRecord csvRecord : parser) {
            records++;
            if (csvRecord.hasComment()) {
                comments++;
            }
        }
    }
    // Comment lines are concatenated, in this example 4 lines become 2 comments.
    Assert.assertEquals(totcomment, comments);
    Assert.assertEquals(totrecs, records); // records includes the header
}
项目:timbuctoo    文件:CsvLoader.java   
@JsonCreator
public CsvLoader(@JsonProperty("config") Map<String, String> config) {
  CSVFormat format = CSVFormat.EXCEL;
  this.config = config;
  if (config.containsKey("delimiter")) {
    format = format.withDelimiter(onlyChar(config, "delimiter"));
  }
  if (config.containsKey("quoteChar")) {
    format = format.withQuote(onlyChar(config, "quoteChar"));
  }
  if (config.containsKey("quoteMode")) {
    format = format.withQuoteMode(QuoteMode.valueOf(config.get("quoteMode")));
  }
  if (config.containsKey("commentStart")) {
    format = format.withCommentMarker(onlyChar(config, "commentStart"));
  }
  if (config.containsKey("escape")) {
    format = format.withEscape(onlyChar(config, "escape"));
  }
  if (config.containsKey("ignoreSurroundingSpaces")) {
    format = format.withIgnoreSurroundingSpaces(config.get("ignoreSurroundingSpaces").equals("true"));
  }
  if (config.containsKey("ignoreEmptyLines")) {
    format = format.withIgnoreEmptyLines(config.get("ignoreEmptyLines").equals("true"));
  }
  if (config.containsKey("recordSeparator")) {
    format = format.withRecordSeparator(config.get("recordSeparator"));
  }
  if (config.containsKey("nullString")) {
    format = format.withNullString(config.get("nullString"));
  }
  if (config.containsKey("trim")) {
    format = format.withTrim(config.get("trim").equals("true"));
  }
  if (config.containsKey("trailingDelimiter")) {
    format = format.withTrailingDelimiter(config.get("trailingDelimiter").equals("true"));
  }
  this.format = format
    .withAllowMissingColumnNames()
    .withHeader();
}
项目:incubator-batchee    文件:CSVFormatFactory.java   
static CSVFormat newFormat(final String format,
                                      final String delimiter,
                                      final String quoteCharacter,
                                      final String quoteMode,
                                      final String commentMarker,
                                      final String escapeCharacter,
                                      final String ignoreSurroundingSpaces,
                                      final String ignoreEmptyLines,
                                      final String recordSeparator,
                                      final String nullString,
                                      final String headerComments,
                                      final String header,
                                      final String skipHeaderRecord,
                                      final String allowMissingColumnNames,
                                      final String readHeaders) {
//CHECKSTYLE:ON
        CSVFormat out = format == null ? CSVFormat.DEFAULT : CSVFormat.valueOf(format);
        if (delimiter != null) {
            out = out.withDelimiter(delimiter.charAt(0));
        }
        if (quoteCharacter != null) {
            out = out.withQuote(quoteCharacter.charAt(0));
        }
        if (quoteMode != null) {
            out = out.withQuoteMode(QuoteMode.valueOf(quoteMode));
        }
        if (commentMarker != null) {
            out = out.withCommentMarker(commentMarker.charAt(0));
        }
        if (escapeCharacter != null) {
            out = out.withEscape(escapeCharacter.charAt(0));
        }
        if (ignoreSurroundingSpaces != null) {
            out = out.withIgnoreSurroundingSpaces(Boolean.parseBoolean(ignoreSurroundingSpaces));
        }
        if (ignoreEmptyLines != null) {
            out = out.withIgnoreEmptyLines(Boolean.parseBoolean(ignoreEmptyLines));
        }
        if (recordSeparator != null) {
            if ("\\n".equals(recordSeparator)) {
                out = out.withRecordSeparator('\n');
            } else if ("\\r\\n".equals(recordSeparator)) {
                out = out.withRecordSeparator("\r\n");
            } else {
                out = out.withRecordSeparator(recordSeparator);
            }
        }
        if (nullString != null) {
            out = out.withNullString(nullString);
        }
        if (headerComments != null && !headerComments.trim().isEmpty()) {
            out = out.withHeaderComments(headerComments.split(" *, *"));
        }
        if (Boolean.parseBoolean(readHeaders)) {
            out = out.withHeader();
        }
        if (header != null && !header.trim().isEmpty()) {
            try { // headers can have CSV header names so parse it there
                final Iterator<CSVRecord> iterator = out.withHeader(new String[0]).parse(new StringReader(header + '\n' + header)).iterator();
                final CSVRecord record = iterator.next();
                final List<String> list = new ArrayList<String>(record.size());
                for (final String h : record) {
                    list.add(h);
                }
                out = out.withHeader(list.toArray(new String[record.size()]));
            } catch (final IOException e) { // can't occur actually
                out = out.withHeader(header.split(" *, *"));
            }
        }
        if (skipHeaderRecord != null) {
            out = out.withSkipHeaderRecord(Boolean.parseBoolean(skipHeaderRecord));
        }
        if (allowMissingColumnNames != null) {
            out = out.withAllowMissingColumnNames(Boolean.parseBoolean(allowMissingColumnNames));
        }
        return out;
    }
项目:Camel    文件:CsvDataFormat.java   
/**
 * Gets the quote mode.
 * If {@code null} then the default one of the format used.
 *
 * @return Quote mode
 */
public QuoteMode getQuoteMode() {
    return quoteMode;
}
项目:Camel    文件:CsvDataFormat.java   
/**
 * Sets the quote mode.
 * If {@code null} then the default one of the format used.
 *
 * @param quoteMode Quote mode
 * @return Current {@code CsvDataFormat}, fluent API
 * @see org.apache.commons.csv.CSVFormat#withQuoteMode(org.apache.commons.csv.QuoteMode)
 */
public CsvDataFormat setQuoteMode(QuoteMode quoteMode) {
    this.quoteMode = quoteMode;
    return this;
}