use of com.univocity.parsers.csv.CsvWriter in project conquery by bakdata.
the class AdminProcessor method getPermissionOverviewAsCSV.
/**
* Renders the permission overview for certain {@link User} in form of a CSV.
*/
public String getPermissionOverviewAsCSV(Collection<User> users) {
StringWriter sWriter = new StringWriter();
CsvWriter writer = config.getCsv().createWriter(sWriter);
List<String> scope = config.getAuthorizationRealms().getOverviewScope();
// Header
writeAuthOverviewHeader(writer, scope);
// Body
for (User user : users) {
writeAuthOverviewUser(writer, scope, user, storage, config);
}
return sWriter.toString();
}
use of com.univocity.parsers.csv.CsvWriter in project droid by digital-preservation.
the class CsvItemWriter method open.
@Override
public void open(final Writer writer) {
final CsvWriterSettings csvWriterSettings = new CsvWriterSettings();
csvWriterSettings.setQuoteAllFields(true);
CsvFormat format = new CsvFormat();
// following Unix convention on line separators as previously
format.setLineSeparator("\n");
csvWriterSettings.setFormat(format);
csvWriter = new CsvWriter(writer, csvWriterSettings);
if (headers == null) {
headers = HEADERS;
}
csvWriter.writeHeaders(headers);
}
use of com.univocity.parsers.csv.CsvWriter in project hillview by vmware.
the class CsvFileTest method csvWriterTest.
@Test
public void csvWriterTest() throws IOException {
// The Csv writer (Univocity) we were using had a bug,
// reproduced with this test.
String[] data = new String[] { "", null };
CsvWriterSettings settings = new CsvWriterSettings();
CsvFormat format = new CsvFormat();
settings.setFormat(format);
settings.setEmptyValue("\"\"");
settings.setNullValue("");
String fileName = "tmp.csv";
Writer fw = new FileWriter(fileName);
CsvWriter writer = new CsvWriter(fw, settings);
writer.writeRow(data);
writer.close();
fw.close();
File file = new File(fileName);
if (file.exists()) {
@SuppressWarnings("unused") boolean ignored = file.delete();
}
}
use of com.univocity.parsers.csv.CsvWriter in project drill by apache.
the class TextRecordWriter method startNewSchema.
@Override
public void startNewSchema(BatchSchema schema) throws IOException {
// wrap up the current file
cleanup();
// open a new file for writing data with new schema
Path fileName = new Path(location, String.format("%s_%s%s", prefix, fileNumberIndex, extension));
try {
// Drill text writer does not support partitions, so only one file can be created
// and thus only one location should be deleted in case of abort
// to ensure that our writer was the first to create output file,
// we create empty output file first and fail if file exists
cleanUpLocation = storageStrategy.createFileAndApply(fs, fileName);
// since empty output file will be overwritten (some file systems may restrict append option)
// we need to re-apply file permission
DataOutputStream fos = fs.create(fileName);
storageStrategy.applyToFile(fs, fileName);
logger.debug("Created file: {}.", fileName);
// increment file number index
fileNumberIndex++;
this.writer = new CsvWriter(fos, writerSettings);
} catch (IOException e) {
throw new IOException(String.format("Unable to create file: %s.", fileName), e);
}
if (writerSettings.isHeaderWritingEnabled()) {
writer.writeHeaders(StreamSupport.stream(schema.spliterator(), false).map(MaterializedField::getName).collect(Collectors.toList()));
}
}
Aggregations