yakworks.etl.csv.CSVMapWriter.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gorm-etl Show documentation
Show all versions of gorm-etl Show documentation
gorm-tools CSV reader helpers
/*
* Copyright 2021 Yak.Works - Licensed under the Apache License, Version 2.0 (the "License")
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
package yakworks.etl.csv
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.apache.commons.beanutils.PropertyUtils
import com.opencsv.CSVWriter
import yakworks.commons.beans.PropertyTools
import yakworks.commons.map.MapFlattener
import yakworks.meta.MetaMapList
@CompileStatic
class CSVMapWriter {
CSVWriter csvWriter
Set headers
CSVMapWriter(Writer outWriter){
this.csvWriter = new CSVWriter(outWriter)
}
static CSVMapWriter of(Writer outWriter){
return new CSVMapWriter(outWriter)
}
void flush(){
csvWriter.flush()
}
void writeHeader(Set headerKeys){
writeNext(csvWriter, headerKeys)
}
/**
* If dataList is a MetaMapList then it will use its metaEntity to get the headers.
* otherwise it creates the header using the the data in the first item of collection.
*/
void createHeader(Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy