当前位置: 首页>>代码示例>>Java>>正文


Java QuoteMode类代码示例

本文整理汇总了Java中org.apache.commons.csv.QuoteMode的典型用法代码示例。如果您正苦于以下问题:Java QuoteMode类的具体用法?Java QuoteMode怎么用?Java QuoteMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QuoteMode类属于org.apache.commons.csv包,在下文中一共展示了QuoteMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: logResults

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
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);
	}
}
 
开发者ID:heindorf,项目名称:cikm16-wdvd-feature-extraction,代码行数:26,代码来源:ActionStatisticsProcessor.java

示例2: importFromCsvFile

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
/**
 * 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();
	}
}
 
开发者ID:fr3ts0n,项目名称:StageFever,代码行数:29,代码来源:SongAdapter.java

示例3: createFormat

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:datascienceinc,项目名称:cascading.csv,代码行数:29,代码来源:CsvInputFormat.java

示例4: createFormat

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:datascienceinc,项目名称:cascading.csv,代码行数:29,代码来源:CsvOutputFormat.java

示例5: getQuoteMode

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
@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;
	}
}
 
开发者ID:lithiumtech,项目名称:flow,代码行数:18,代码来源:CsvFormats.java

示例6: createEndChannel

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:commons-csv,代码行数:26,代码来源:JiraCsv213Test.java

示例7: createFormat

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:24,代码来源:AbstractCsvLayout.java

示例8: createLayout

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:21,代码来源:CsvParameterLayout.java

示例9: createLayout

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:21,代码来源:CsvLogEventLayout.java

示例10: joinPMMLDelimitedNumbers

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
/**
 * @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);
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:11,代码来源:TextUtils.java

示例11: processLoincFiles

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
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());
}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:34,代码来源:RITerminologyLoader.java

示例12: CsvWriterService

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
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();
	}
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:10,代码来源:CsvWriterService.java

示例13: shouldOverrideQuoteMode

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
@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());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:CsvDataFormatTest.java

示例14: testQuoteModeAll

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:commons-csv,代码行数:14,代码来源:JiraCsv203Test.java

示例15: testQuoteModeAllNonNull

import org.apache.commons.csv.QuoteMode; //导入依赖的package包/类
@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());
}
 
开发者ID:apache,项目名称:commons-csv,代码行数:14,代码来源:JiraCsv203Test.java


注:本文中的org.apache.commons.csv.QuoteMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。