本文整理汇总了Java中org.supercsv.quote.AlwaysQuoteMode类的典型用法代码示例。如果您正苦于以下问题:Java AlwaysQuoteMode类的具体用法?Java AlwaysQuoteMode怎么用?Java AlwaysQuoteMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AlwaysQuoteMode类属于org.supercsv.quote包,在下文中一共展示了AlwaysQuoteMode类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCustomPreference
import org.supercsv.quote.AlwaysQuoteMode; //导入依赖的package包/类
/**
* Tests a custom CsvPreference with supplied optional values.
*/
@Test
public void testCustomPreference() {
final CsvPreference custom = new CsvPreference.Builder('"', ',', "\n")
.surroundingSpacesNeedQuotes(true)
.useEncoder(new DefaultCsvEncoder())
.useQuoteMode(new AlwaysQuoteMode())
.setQuoteEscapeChar('\\')
.build();
assertEquals('"', custom.getQuoteChar());
assertEquals(',', custom.getDelimiterChar());
assertEquals("\n", custom.getEndOfLineSymbols());
assertTrue(custom.isSurroundingSpacesNeedQuotes());
assertTrue(custom.getEncoder() instanceof DefaultCsvEncoder);
assertTrue(custom.getQuoteMode() instanceof AlwaysQuoteMode);
assertEquals('\\', custom.getQuoteEscapeChar());
}
示例2: testCustomPreferenceBasedOnExisting
import org.supercsv.quote.AlwaysQuoteMode; //导入依赖的package包/类
/**
* Tests a custom CsvPreference based on an existing constant with supplied optional values.
*/
@Test
public void testCustomPreferenceBasedOnExisting() {
final CsvPreference custom = new CsvPreference.Builder(EXCEL_PREFERENCE).surroundingSpacesNeedQuotes(true)
.useEncoder(new DefaultCsvEncoder()).useQuoteMode(new AlwaysQuoteMode()).build();
assertEquals(EXCEL_PREFERENCE.getQuoteChar(), custom.getQuoteChar());
assertEquals(EXCEL_PREFERENCE.getDelimiterChar(), custom.getDelimiterChar());
assertEquals(EXCEL_PREFERENCE.getEndOfLineSymbols(), custom.getEndOfLineSymbols());
assertTrue(custom.isSurroundingSpacesNeedQuotes());
assertTrue(custom.getEncoder() instanceof DefaultCsvEncoder);
assertTrue(custom.getQuoteMode() instanceof AlwaysQuoteMode);
assertEquals(EXCEL_PREFERENCE.getQuoteEscapeChar(), custom.getQuoteEscapeChar());
}
示例3: testWriteAll_custom_preference
import org.supercsv.quote.AlwaysQuoteMode; //导入依赖的package包/类
/**
* 書き込みのテスト - {@link CsvPreference}のカスタマイズ
*/
@Test
public void testWriteAll_custom_preference() throws IOException {
// テストデータの作成
final List<SampleNormalBean> list = createNormalData();
StringWriter strWriter = new StringWriter();
// タブ区切り、改行コード「LF」、必ずダブルクウォートで囲む設定
final CsvPreference preference = new CsvPreference.Builder('\"', '\t', "\n")
.useQuoteMode(new AlwaysQuoteMode())
.build();
CsvAnnotationBeanWriter<SampleNormalBean> csvWriter = new CsvAnnotationBeanWriter<>(
SampleNormalBean.class,
strWriter,
preference,
DefaultGroup.class, SampleNormalBean.WriteGroup.class);
csvWriter.writeAll(list, true);
csvWriter.flush();
String actual = strWriter.toString();
System.out.println(actual);
String expected = getTextFromFile("src/test/data/test_write_tab.csv", Charset.forName("UTF-8"));
assertThat(actual).isEqualTo(expected);
assertThat(csvWriter.getErrorMessages()).hasSize(0);
csvWriter.close();
}