本文整理汇总了Java中org.supercsv.io.ICsvBeanWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java ICsvBeanWriter.close方法的具体用法?Java ICsvBeanWriter.close怎么用?Java ICsvBeanWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.supercsv.io.ICsvBeanWriter
的用法示例。
在下文中一共展示了ICsvBeanWriter.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCsv
import org.supercsv.io.ICsvBeanWriter; //导入方法依赖的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();
}
}
}
示例2: downloadCSV
import org.supercsv.io.ICsvBeanWriter; //导入方法依赖的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();
}
示例3: csvWrite
import org.supercsv.io.ICsvBeanWriter; //导入方法依赖的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");
}
示例4: downloadCSV
import org.supercsv.io.ICsvBeanWriter; //导入方法依赖的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();
}