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


Java CsvBeanWriter.close方法代码示例

本文整理汇总了Java中org.supercsv.io.CsvBeanWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java CsvBeanWriter.close方法的具体用法?Java CsvBeanWriter.close怎么用?Java CsvBeanWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.supercsv.io.CsvBeanWriter的用法示例。


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

示例1: getCsv

import org.supercsv.io.CsvBeanWriter; //导入方法依赖的package包/类
@RequestMapping(value = "/csv", method = RequestMethod.GET, produces = "text/csv;charset=utf-8")
public String getCsv() throws IOException {
    log.info("CSV request");
    StringWriter writer = new StringWriter();
    final CsvBeanWriter csvBeanWriter = new CsvBeanWriter(writer, CsvPreference.STANDARD_PREFERENCE);
    final String[] header = {"uuid", "userName", "error", "correctForm", "createdDate"};
    csvBeanWriter.writeHeader(header);
    mistakeRepository.findAll().forEach(
            (mistake) -> {
                try {
                    csvBeanWriter.write(mistake, header);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
    );
    csvBeanWriter.close();
    return writer.toString();
}
 
开发者ID:softwaremill,项目名称:janusz-backend,代码行数:20,代码来源:DataServingController.java

示例2: getAllMoods

import org.supercsv.io.CsvBeanWriter; //导入方法依赖的package包/类
@RequestMapping(value = "/all_moods.csv", method = RequestMethod.GET, produces = "text/csv")
public String getAllMoods() throws IOException {
    StringWriter writer = new StringWriter();
    final CsvBeanWriter csvBeanWriter = new CsvBeanWriter(writer, CsvPreference.STANDARD_PREFERENCE);
    final String[] header = {"id", "userName", "userId", "mood", "description", "createdDate"};
    csvBeanWriter.writeHeader(header);
    moodRepository.findAll().forEach(
            (mood) -> {
                try {
                    csvBeanWriter.write(mood, header);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
    );
    csvBeanWriter.close();
    return writer.toString();
}
 
开发者ID:softwaremill,项目名称:janusz-backend,代码行数:19,代码来源:MoodRestController.java

示例3: testDateSupport

import org.supercsv.io.CsvBeanWriter; //导入方法依赖的package包/类
@Test
public void testDateSupport() throws IOException {
	Calendar calendar = Calendar.getInstance();
	calendar.set(Calendar.YEAR, 1999);
	calendar.set(Calendar.MONTH, 6);
	calendar.set(Calendar.DAY_OF_MONTH, 12);
	
	FeatureBean character = new FeatureBean("John", "Connor", 16);
	character.setBirthDate(calendar.getTime());
	
	String[] mapping = { "birthDate" };
	DecimalFormat formatter = new DecimalFormat();
	formatter.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance());
	CellProcessor[] processors = { new FmtDate("yyyy-MM-dd") };
	
	StringWriter writer = new StringWriter();
	CsvBeanWriter beanWriter = new CsvBeanWriter(writer, STANDARD_PREFERENCE);
	beanWriter.write(character, mapping, processors);
	beanWriter.close();
	
	String csv = writer.toString();
	Assert.assertNotNull(csv);
	Assert.assertEquals("1999-07-12\r\n", csv);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:25,代码来源:WritingFeaturesTest.java

示例4: testColumnNameBasedMapping

import org.supercsv.io.CsvBeanWriter; //导入方法依赖的package包/类
@Test
public void testColumnNameBasedMapping() throws IOException {
	FeatureBean character = new FeatureBean("John", "Connor", 16);
	String[] mapping = { "lastName", "firstName" };
	StringWriter writer = new StringWriter();
	CsvBeanWriter beanWriter = new CsvBeanWriter(writer, STANDARD_PREFERENCE);
	beanWriter.write(character, mapping);
	beanWriter.close();
	
	String csv = writer.toString();
	Assert.assertNotNull(csv);
	Assert.assertEquals("Connor,John\r\n", csv);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:14,代码来源:WritingFeaturesTest.java

示例5: testConvertsToPrimitives

import org.supercsv.io.CsvBeanWriter; //导入方法依赖的package包/类
@Test
public void testConvertsToPrimitives() throws IOException {
	FeatureBean character = new FeatureBean("John", "Connor", 16);
	String[] mapping = { "lastName", "firstName", "age" };
	
	StringWriter writer = new StringWriter();
	CsvBeanWriter beanWriter = new CsvBeanWriter(writer, STANDARD_PREFERENCE);
	beanWriter.write(character, mapping);
	beanWriter.close();
	
	String csv = writer.toString();
	Assert.assertNotNull(csv);
	Assert.assertEquals("Connor,John,16\r\n", csv);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:15,代码来源:WritingFeaturesTest.java

示例6: testConvertsToBasicObjects

import org.supercsv.io.CsvBeanWriter; //导入方法依赖的package包/类
@Test
public void testConvertsToBasicObjects() throws IOException {
	Calendar calendar = Calendar.getInstance();
	calendar.set(Calendar.YEAR, 1999);
	calendar.set(Calendar.MONTH, 6);
	calendar.set(Calendar.DAY_OF_MONTH, 12);
	
	FeatureBean character = new FeatureBean("John", "Connor", 16);
	character.setSavings(new BigDecimal(6.65));
	character.setBirthDate(calendar.getTime());
	
	String[] mapping = { "lastName", "firstName", "age", "birthDate", "savings" };
	DecimalFormat formatter = new DecimalFormat();
	formatter.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance());
	CellProcessor[] processors = { new NotNull(), new NotNull(), new NotNull(), new FmtDate("yyyy-MM-dd"),
		new FmtNumber(formatter) };
	
	StringWriter writer = new StringWriter();
	CsvPreference customPreference = new Builder('"', '|', "\r\n").build();
	CsvBeanWriter beanWriter = new CsvBeanWriter(writer, customPreference);
	beanWriter.write(character, mapping, processors);
	beanWriter.close();
	
	String csv = writer.toString();
	Assert.assertNotNull(csv);
	Assert.assertEquals("Connor|John|16|1999-07-12|" + formatter.format(character.getSavings()) + "\r\n", csv);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:28,代码来源:WritingFeaturesTest.java

示例7: testConverterSupport

import org.supercsv.io.CsvBeanWriter; //导入方法依赖的package包/类
@Test
public void testConverterSupport() throws IOException {
	Calendar calendar = Calendar.getInstance();
	calendar.set(Calendar.YEAR, 1999);
	calendar.set(Calendar.MONTH, 6);
	calendar.set(Calendar.DAY_OF_MONTH, 12);
	
	FeatureBean character = new FeatureBean("John", "Connor", 16);
	character.setSavings(new BigDecimal(6.65));
	character.setBirthDate(calendar.getTime());
	
	String[] mapping = { "lastName", "firstName", "age", "birthDate", "savings" };
	DecimalFormat formatter = new DecimalFormat();
	formatter.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance());
	CellProcessor[] processors = { new NotNull(), new NotNull(), new NotNull(), new FmtDate("yyyy-MM-dd"),
		new FmtNumber(formatter) };
	
	StringWriter writer = new StringWriter();
	CsvPreference customPreference = new Builder('"', '|', "\r\n").build();
	CsvBeanWriter beanWriter = new CsvBeanWriter(writer, customPreference);
	beanWriter.write(character, mapping, processors);
	beanWriter.close();
	
	String csv = writer.toString();
	Assert.assertNotNull(csv);
	Assert.assertEquals("Connor|John|16|1999-07-12|" + formatter.format(character.getSavings()) + "\r\n", csv);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:28,代码来源:WritingFeaturesTest.java


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