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


Java CsvBeanWriter类代码示例

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


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

示例1: getCsv

import org.supercsv.io.CsvBeanWriter; //导入依赖的package包/类
@RequestMapping(value = "/exportCsvFile/{stats}", method = RequestMethod.GET)
public void getCsv(@PathVariable("stats") String stats, HttpServletRequest request, HttpServletResponse response, Locale locale) throws UnsupportedEncodingException, IOException {
	
	response.setContentType("text/csv");
	String reportName = "editable.csv";
	response.setHeader("Set-Cookie", "fileDownload=true; path=/");
	response.setHeader("Content-disposition", "attachment;filename=" + reportName);
	
	final String[] header = exportService.getHeader(stats);
	
	Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF8");
	
	ICsvBeanWriter beanWriter =  new CsvBeanWriter(writer, CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);

	beanWriter.writeHeader(header);
	
	try{
		List<ExportBean>  objs = exportService.getBean(stats, locale);
		for(ExportBean item : objs) {
			beanWriter.write(item, header);
		}
		beanWriter.flush();
		
		writer.close();
		
	}catch(Exception e){
		log.error("interruption de l'export !",e);
	} finally {
           if( beanWriter != null ) {
               beanWriter.close();
           }
	}
		
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:35,代码来源:ImportExportController.java

示例2: downloadCSV

import org.supercsv.io.CsvBeanWriter; //导入依赖的package包/类
@RequestMapping("download-csv/{id}")
public void downloadCSV(HttpServletResponse response, @PathVariable("id") Long id) throws IOException {
    final Material material = materialRepository.findOne(id);
    if (material == null)
        throw new IllegalArgumentException("[" + id + "] data is not exist.");

    String videoName = material.getVideoName();
    int lastIndexOf = videoName.lastIndexOf("/");
    videoName = lastIndexOf >= 0 ? videoName.substring(lastIndexOf + 1, videoName.length()) : videoName;
    final String csvFileName = videoName + "_" + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(material.getCreatedAt())) + ".csv";

    response.setContentType("text/csv");

    String headerKey = "Content-Disposition";
    String headerValue = String.format("attachment; filename=\"%s\"", csvFileName);
    response.setHeader(headerKey, headerValue);

    final ICsvBeanWriter csvWriter = new CsvBeanWriter(response.getWriter(), CsvPreference.STANDARD_PREFERENCE);
    final String[] header = {"timestamp", "key"};
    csvWriter.writeHeader(header);

    for (MaterialData data : material.getMaterialDataList())
        csvWriter.write(data, header);

    csvWriter.close();
}
 
开发者ID:tinywind,项目名称:video-streaming-service,代码行数:27,代码来源:MainController.java

示例3: 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

示例4: 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

示例5: 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

示例6: csvWrite

import org.supercsv.io.CsvBeanWriter; //导入依赖的package包/类
@Transactional(readOnly=true)
public void csvWrite(Writer writer, List<PosteCandidature> posteCandidatures) throws IOException {

	log.info("Generate CSV for " + posteCandidatures.size() + " posteCandidatures");
	
	final String[] header = new String[] { "poste", "nom", "email", "prenom", "galaxie", "recevable", "auditionnable", "vue", "creation", "modification", "gestionnaire", "dateGestion"};
	final CellProcessor[] processors = getProcessors();
	
	ICsvBeanWriter beanWriter =  new CsvBeanWriter(writer, CsvPreference.STANDARD_PREFERENCE);
	beanWriter.writeHeader(header);
	
	for (PosteCandidature posteCandidature : posteCandidatures) {
		CsvPosteCandidatureMetadataFileBean csvMetadataFileBean = new CsvPosteCandidatureMetadataFileBean(posteCandidature);
		beanWriter.write(csvMetadataFileBean, header, processors);
	}
	beanWriter.close();
	
	log.info("Generate CSV OK");
}
 
开发者ID:EsupPortail,项目名称:esup-dematec,代码行数:20,代码来源:CsvService.java

示例7: createCitationFile

import org.supercsv.io.CsvBeanWriter; //导入依赖的package包/类
/**
 * Creates the dataset citation file using the the Solr query response.
 *
 * @param datasetUsages          record count per dataset
 * @param citationFileName       output file name
 * @param datasetOccUsageService usage service
 * @param downloadKey            download key
 */
public static void createCitationFile(Map<UUID, Long> datasetUsages, String citationFileName,
                                      DatasetOccurrenceDownloadUsageService datasetOccUsageService,
                                      DatasetService datasetService, String downloadKey) {
  if (datasetUsages != null && !datasetUsages.isEmpty()) {
    try (ICsvBeanWriter beanWriter = new CsvBeanWriter(new FileWriterWithEncoding(citationFileName, Charsets.UTF_8),
                                                       CsvPreference.TAB_PREFERENCE)) {
      for (Entry<UUID, Long> entry : datasetUsages.entrySet()) {
        if (entry.getKey() != null) {
          beanWriter.write(new Facet.Count(entry.getKey().toString(), entry.getValue()), HEADER, PROCESSORS);
          persistDatasetUsage(entry, downloadKey, datasetOccUsageService, datasetService);
        }
      }
      beanWriter.flush();
    } catch (IOException e) {
      LOG.error("Error creating citations file", e);
      throw Throwables.propagate(e);
    }
  }
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:28,代码来源:CitationsFileWriter.java

示例8: downloadCSV

import org.supercsv.io.CsvBeanWriter; //导入依赖的package包/类
private void downloadCSV(final HttpServletResponse response, final List<EventLoggerDTO> events,
    final int processModelId, final String subject) throws IOException {
  final String date = DateTime.now().toString("ddMMyyyy-HHmm");
  final String csvFileName = "Eventlog_" + processModelId + "_" + subject + "_" + date + ".csv";

  response.setContentType("text/csv");

  final String headerKey = "Content-Disposition";
  final String headerValue = String.format("attachment; filename=\"%s\"", csvFileName);
  response.setHeader(headerKey, headerValue);

  // uses the Super CSV API to generate CSV data from the model data
  final ICsvBeanWriter csvWriter =
      new CsvBeanWriter(response.getWriter(), CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);

  final String[] header =
      {"EventId", "CaseId", "Timestamp", "Activity", "Resource", "State", "MessageType", "Recipient", "Sender"};

  csvWriter.writeHeader(header);
  events.forEach(event -> {
    try {
      if (!event.getResource().isEmpty()) {
        csvWriter.write(event, header);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  });

  csvWriter.close();
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:32,代码来源:EventLoggerController.java

示例9: CsvTickWriter

import org.supercsv.io.CsvBeanWriter; //导入依赖的package包/类
public CsvTickWriter(String symbol) throws IOException {

		File file = new File("results/tickdata/" + dataSet + "/" + symbol + ".csv");
		boolean exists = file.exists();

		this.writer = new CsvBeanWriter(new FileWriter(file, true), CsvPreference.EXCEL_PREFERENCE);

		if (!exists) {
			this.writer.writeHeader(header);
		}
	}
 
开发者ID:curtiszimmerman,项目名称:AlgoTrader,代码行数:12,代码来源:CsvTickWriter.java

示例10: exportStream

import org.supercsv.io.CsvBeanWriter; //导入依赖的package包/类
@Override
public void exportStream(OutputStream outputStream, Iterator<T> iterator) throws IOException, ClassNotFoundException, IllegalAccessException {
    if (iterator == null)
        throw new NullPointerException("List can not be null or empty.");

    Writer writer = new OutputStreamWriter(outputStream, "UTF-8");

    ICsvBeanWriter beanWriter = new CsvBeanWriter(writer, preference);

    while (iterator.hasNext()) {
        T entry = iterator.next();
        beanWriter.write(entry, fieldNames, processors);
    }
    beanWriter.flush();
}
 
开发者ID:robeio,项目名称:robe,代码行数:16,代码来源:CSVExporter.java

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: testWriteToWriter

import org.supercsv.io.CsvBeanWriter; //导入依赖的package包/类
@Test
public void testWriteToWriter() throws IOException {
	StringWriter writer = new StringWriter();
	new CsvListWriter(writer, STANDARD_PREFERENCE);
	new CsvMapWriter(writer, STANDARD_PREFERENCE);
	new CsvBeanWriter(writer, STANDARD_PREFERENCE);
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:8,代码来源:WritingFeaturesTest.java


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