本文整理汇总了Java中com.univocity.parsers.csv.CsvWriter类的典型用法代码示例。如果您正苦于以下问题:Java CsvWriter类的具体用法?Java CsvWriter怎么用?Java CsvWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CsvWriter类属于com.univocity.parsers.csv包,在下文中一共展示了CsvWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testMapWithUnexpectedHeaders
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Test
public void testMapWithUnexpectedHeaders() {
OutputValueSwitch writerSwitch = new OutputValueSwitch("type");
writerSwitch.addSwitchForValue("SUPER", new ObjectRowWriterProcessor(), "type", "h1", "h2", "h3", "h4");
writerSwitch.addSwitchForValue("DUPER", new ObjectRowWriterProcessor(), "type", "h4", "Z1", "Z3", "h1");
CsvWriterSettings settings = new CsvWriterSettings();
settings.setExpandIncompleteRows(true);
settings.getFormat().setLineSeparator("\n");
settings.setHeaderWritingEnabled(false);
settings.setRowWriterProcessor(writerSwitch);
StringWriter output = new StringWriter();
CsvWriter writer = new CsvWriter(output, settings);
writer.writeRow(newMap("SUPER", "Z1=>v1;h2=>v2;h3=>v3;h4=>v4"));
writer.writeRow(newMap("DUPER", "Z1=>v1;h2=>v2;Z3=>v3;h4=>v4"));
writer.close();
assertEquals(output.toString(), "" +
"SUPER,,v2,v3,v4\n" +
"DUPER,v4,v1,v3,\n");
}
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:24,代码来源:Github_66.java
示例2: testAppendAndExpandWhenAppendingChar
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Test
public void testAppendAndExpandWhenAppendingChar() {
CsvWriterSettings settings = new CsvWriterSettings();
settings.getFormat().setLineSeparator("\n");
settings.getFormat().setDelimiter('\t');
settings.setMaxCharsPerColumn(16); // note default max length before expanding
settings.getFormat().setQuote('"');
settings.getFormat().setQuoteEscape('"');
settings.setIgnoreLeadingWhitespaces(false);
settings.setIgnoreTrailingWhitespaces(false);
settings.setQuoteAllFields(true);
settings.setEmptyValue("");
StringWriter stringWriter = new StringWriter();
CsvWriter writer = new CsvWriter(stringWriter, settings);
// test data's first column length is specific to repro bug occuring due to
// appending quote character occuring at writer buffer boundary
String[] testCase = {"abcdefghijklmno", "pqrst", "uvwxyz"};
String expectedString = "\"abcdefghijklmno\"\t\"pqrst\"\t\"uvwxyz\"\n";
writer.writeRow(testCase);
writer.close();
assertEquals(stringWriter.toString(), expectedString);
}
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:27,代码来源:WriterCharAppenderTest.java
示例3: testRowExpansion
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Test
public void testRowExpansion() {
StringWriter output = new StringWriter();
CsvWriterSettings settings = new CsvWriterSettings();
settings.setExpandIncompleteRows(true);
settings.getFormat().setLineSeparator("\n");
settings.setHeaderWritingEnabled(true);
settings.setHeaders("A", "B", "C", "D", "E", "F");
CsvWriter writer = new CsvWriter(output, settings);
writer.writeRow();
writer.writeRow("V1", "V2", "V3");
writer.writeRow("V1", "V2", "V3", 4, 5);
writer.writeRow("V1", "V2", "V3", 4, 5, 6);
writer.close();
assertEquals(output.toString(), "A,B,C,D,E,F\n,,,,,\nV1,V2,V3,,,\nV1,V2,V3,4,5,\nV1,V2,V3,4,5,6\n");
}
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:21,代码来源:AbstractWriterTest.java
示例4: writeBlocks
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
public void writeBlocks(List<BlockWithData> blocks, String pathToFile) {
CsvWriter csvWriter = dataParser.preparOutputFile(pathToFile);
if (csvWriter != null) {
// Write the record headers of this file
List<String> fieldsNames = getBlockFieldsNames(blocks);
fieldsNames.add("Probability");
csvWriter.writeHeaders(fieldsNames);
// Let's write the rows one by one
for (BlockWithData block : blocks) {
for (Record record : block.getMembers()) {
for (String recordEntry : record.getEntries()) {
csvWriter.writeValue(recordEntry);
}
csvWriter.writeValues(block.getMemberProbability(record));
csvWriter.writeValuesToRow();
}
}
// Here we just tell the writer to write everything and close the given output Writer instance.
csvWriter.close();
}
}
开发者ID:sapirgolan,项目名称:MFIBlocking,代码行数:23,代码来源:ParsingService.java
示例5: writeExperimentsMeasurements
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
public void writeExperimentsMeasurements(IMeasurements measurements, File tempFile) throws SizeNotEqualException {
CsvWriter csvWriter = dataParser.preparOutputFile(tempFile);
csvWriter.writeHeaders(THRESHOLD, RANKED_VALUE, MRR, NORM_RANKED_VALUE, NORM_MRR, MILLER_RANKED_VALUE, MILLER_MRR_VALUE);
List<Double> mrrValues = measurements.getMrrValuesSortedByThreshold();
List<Double> rankedValues = measurements.getRankedValuesSortedByThreshold();
List<Double> thresholds = measurements.getThresholdSorted();
List<Double> normalizedRankedValues = measurements.getNormalizedRankedValuesSortedByThreshold();
List<Double> normalizedMRRValues = measurements.getNormalizedMRRValuesSortedByThreshold();
assertSize(measurements);
Double millerRankedValue = getMillerRankedValue(rankedValues);
Double millerMRRValue = getMillerMRRValue(mrrValues);
for (int i = 1; i < thresholds.size(); i++) {
csvWriter.writeValue(MRR, mrrValues.get(i));
csvWriter.writeValue(THRESHOLD, thresholds.get(i));
csvWriter.writeValue(RANKED_VALUE, rankedValues.get(i));
csvWriter.writeValue(NORM_RANKED_VALUE, normalizedRankedValues.get(i));
csvWriter.writeValue(NORM_MRR, normalizedMRRValues.get(i));
csvWriter.writeValue(MILLER_RANKED_VALUE, millerRankedValue);
csvWriter.writeValue(MILLER_MRR_VALUE, millerMRRValue);
csvWriter.writeValuesToRow();
}
csvWriter.close();
}
开发者ID:sapirgolan,项目名称:MFIBlocking,代码行数:27,代码来源:ParsingService.java
示例6: createString
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Override
public String createString(int rowsToGenerate) {
StringWriter stringWriter = new StringWriter();
CsvWriter csvWriter = new CsvWriter(stringWriter, csvWriterSettings);
writeValues(csvWriter, rowsToGenerate);
return stringWriter.toString();
}
开发者ID:AussieGuy0,项目名称:SDgen,代码行数:8,代码来源:CsvFactory.java
示例7: writeValues
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
private void writeValues(CsvWriter writer, int rowsToGenerate) {
Records records = recordFactory.generateRecords(rowsToGenerate);
if (settings.isIncludingHeaders()) {
records.getFields().forEach(writer::addValue);
writer.writeValuesToRow();
}
records.forEach(record -> {
record.forEach(writer::addValue);
writer.writeValuesToRow();
});
writer.close();
}
开发者ID:AussieGuy0,项目名称:SDgen,代码行数:13,代码来源:CsvFactory.java
示例8: writeTable
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
public void writeTable(ITable table) throws IOException {
Schema schema = table.getSchema();
ColumnAndConverterDescription[] ccds =
ColumnAndConverterDescription.create(schema.getColumnNames());
ColumnAndConverter[] cols = table.getLoadedColumns(ccds);
CsvWriterSettings settings = new CsvWriterSettings();
CsvFormat format = new CsvFormat();
format.setDelimiter(this.separator);
settings.setFormat(format);
settings.setEmptyValue("\"\"");
settings.setNullValue(null);
try (Writer fw = new FileWriter(this.file.toString())) {
CsvWriter writer = new CsvWriter(fw, settings);
String[] data = new String[schema.getColumnCount()];
int index = 0;
for (String c : schema.getColumnNames()) {
data[index] = c;
index++;
}
if (this.writeHeaderRow)
writer.writeHeaders(data);
IRowIterator rowIter = table.getMembershipSet().getIterator();
int nextRow = rowIter.getNextRow();
while (nextRow >= 0) {
for (index = 0; index < cols.length; index++) {
String d = cols[index].isMissing(nextRow) ? null : cols[index].asString(nextRow);
data[index] = d;
}
writer.writeRow(data);
nextRow = rowIter.getNextRow();
}
}
}
开发者ID:vmware,项目名称:hillview,代码行数:36,代码来源:CsvFileWriter.java
示例9: csvWriterTest
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
public void csvWriterTest() throws IOException {
// The Csv writer we are using has 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("");
Writer fw = new FileWriter("tmp");
CsvWriter writer = new CsvWriter(fw, settings);
writer.writeRow(data);
writer.close();
fw.close();
}
开发者ID:vmware,项目名称:hillview,代码行数:15,代码来源:CsvReaderTest.java
示例10: writeToStream
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
public void writeToStream(DataFrame df, Writer out) throws IOException {
String[] columnNames = df.getSchema().getColumnNames().toArray(new String[0]);
CsvWriter writer = new CsvWriter(out, new CsvWriterSettings());
writer.writeHeaders(columnNames);
List<Row> rows = df.getRows();
for (Row curRow : rows) {
List<Object> rowValues = curRow.getVals();
writer.writeRow(rowValues);
}
writer.close();
}
开发者ID:stanford-futuredata,项目名称:macrobase,代码行数:13,代码来源:CSVDataFrameWriter.java
示例11: testException
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Test(expectedExceptions = TextWritingException.class)
public void testException(){
CsvWriterSettings settings = new CsvWriterSettings();
settings.setHeaders("col2", "col5", "col3", "col4", "col1", "col6");
StringWriter out = new StringWriter();
CsvWriter writer = new CsvWriter(out, settings);
Map<String, Object> rowData = new HashMap<String, Object>();
for (int i = 1; i <= 4; i++) {
rowData.put("col" + i, "inh" + i);
}
writer.processRecord(rowData);
}
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:15,代码来源:Github_69.java
示例12: testMapRecords
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Test(expectedExceptions = DataProcessingException.class)
public void testMapRecords() {
final ObjectRowWriterProcessor clientProcessor = new ObjectRowWriterProcessor();
final ObjectRowWriterProcessor accountProcessor = new ObjectRowWriterProcessor();
OutputValueSwitch writerSwitch = new OutputValueSwitch();
writerSwitch.addSwitchForValue("Account", accountProcessor, "type", "balance", "bank", "account", "swift");
writerSwitch.addSwitchForValue("Client", clientProcessor);
CsvWriterSettings settings = new CsvWriterSettings();
settings.setExpandIncompleteRows(true);
settings.getFormat().setLineSeparator("\n");
settings.setHeaderWritingEnabled(false);
settings.setRowWriterProcessor(writerSwitch);
StringWriter output = new StringWriter();
CsvWriter writer = new CsvWriter(output, settings);
Map<String, Object> rowData = new LinkedHashMap<String, Object>();
rowData.put("balance", "sp2");
rowData.put("type", "Account"); //account NOT in first position to force an exception to happen.
rowData.put("bank", "sp3");
rowData.put("acount", "sp4");
rowData.put("swift", "sp5");
writer.processRecord(rowData);
writer.close();
}
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:29,代码来源:Github_66.java
示例13: testMultiple
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Test
public void testMultiple() {
OutputValueSwitch writerSwitch = new OutputValueSwitch("type");
writerSwitch.addSwitchForValue("SUPER", new ObjectRowWriterProcessor(), "type", "h1", "h2", "h3", "h4");
writerSwitch.addSwitchForValue("SUB1", new ObjectRowWriterProcessor(), "type", "a", "b", "c", "d", "e", "f", "g");
writerSwitch.addSwitchForValue("SUB2", new ObjectRowWriterProcessor(), "type", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
CsvWriterSettings settings = new CsvWriterSettings();
settings.setExpandIncompleteRows(true);
settings.getFormat().setLineSeparator("\n");
settings.setHeaderWritingEnabled(false);
settings.setRowWriterProcessor(writerSwitch);
StringWriter output = new StringWriter();
CsvWriter writer = new CsvWriter(output, settings);
writer.writeRow(newMap("SUPER", "h1=>v1;h2=>v2;h3=>v3;h4=>v4"));
writer.writeRow(newMap("SUB1", "a=>v5;d=>v6;e=>v7;g=>v8"));
writer.writeRow(newMap("SUB2", "q=>v9;u=>v10;w=>v11;y=>v12"));
writer.writeRow(newMap("SUB1", "a=>v13;d=>v14;g=>v15"));
writer.writeRow(newMap("SUB1", "a=>v16;d=>v17;f=>v18"));
writer.close();
assertEquals(output.toString(), "" +
"SUPER,v1,v2,v3,v4\n" +
"SUB1,v5,,,v6,v7,,v8\n" +
"SUB2,,v9,,,,v10,,v11,,v12,\n" +
"SUB1,v13,,,v14,,,v15\n" +
"SUB1,v16,,,v17,,v18,\n");
}
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:32,代码来源:Github_66.java
示例14: writeDuplicateReductionContext
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
private void writeDuplicateReductionContext(DuplicateReductionContext duplicateReductionContext, CsvWriter csvWriter) {
csvWriter.writeValue("Missing Real Representatives", duplicateReductionContext.getRepresentationDiff());
csvWriter.writeValue("Duplicates Real Representatives", duplicateReductionContext.getDuplicatesRealRepresentatives());
csvWriter.writeValue("duplicatesRemoved", duplicateReductionContext.getDuplicatesRemoved());
csvWriter.writeValue("Power of Real Reap - Recall", duplicateReductionContext.getRepresentativesPower());
csvWriter.writeValue("Wisdom of the crowd - Precision", duplicateReductionContext.getWisdomCrowds());
csvWriter.writeValue("Average number of blocks", duplicateReductionContext.getNumberOfDirtyBlocks());
csvWriter.writeValue("Average block size", duplicateReductionContext.getAverageBlockSize());
csvWriter.writeValuesToRow();
}
开发者ID:sapirgolan,项目名称:MFIBlocking,代码行数:12,代码来源:ParsingService.java
示例15: writeComparisonExperimentsMeasurements
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
public void writeComparisonExperimentsMeasurements(Multimap<String, DuplicateReductionContext> results, File expResults) {
CsvWriterSettings settings = new CsvWriterSettings();
settings.setHeaders(HEADERS_BASELINE_AND_ALG);
settings.selectFields(HEADERS_BASELINE_AND_ALG);
CsvWriter csvWriter = dataParser.preparOutputFile(expResults, settings);
csvWriter.writeHeaders();
for (Map.Entry<String, DuplicateReductionContext> entry : results.entries()) {
csvWriter.writeRow(buildComparisonRow(entry));
}
csvWriter.close();
}
开发者ID:sapirgolan,项目名称:MFIBlocking,代码行数:14,代码来源:ParsingService.java
示例16: getSHA256Checksum
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
/**
* Returns a hex-encoded MD5 checksum for the given data
*
* @param iterator
* @return
* @throws NoSuchAlgorithmException
*/
public String getSHA256Checksum(final Iterator<String[]> iterator) throws NoSuchAlgorithmException {
// Initialize message digest
MessageDigest md = MessageDigest.getInstance("SHA-256");
DigestOutputStream dis = new DigestOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
// Simply drop the data
}
}, md);
CsvWriter csvwriter = new CsvWriter(new OutputStreamWriter(dis), settings);
// Write
while (iterator.hasNext()) {
csvwriter.writeRow((Object[]) iterator.next());
}
csvwriter.close();
// Obtain digest
byte[] digest = md.digest();
// And convert to hex
StringBuilder builder = new StringBuilder();
for (int i = 0; i < digest.length; i++) {
builder.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
}
return builder.toString();
}
开发者ID:arx-deidentifier,项目名称:arx,代码行数:36,代码来源:CSVDataChecksum.java
示例17: write
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
/**
* Write the results.
*
* @param iterator the iterator
* @throws IOException Signals that an I/O exception has occurred.
*/
public void write(final Iterator<String[]> iterator) throws IOException {
CsvWriter csvwriter = new CsvWriter(writer, settings);
while (iterator.hasNext()) {
csvwriter.writeRow((Object[]) iterator.next());
}
if (close) {
csvwriter.close();
} else {
csvwriter.flush();
}
}
开发者ID:arx-deidentifier,项目名称:arx,代码行数:19,代码来源:CSVDataOutput.java
示例18: createFile
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Override
public File createFile(File file, int rowsToGenerate) {
CsvWriter csvWriter = new CsvWriter(file, csvWriterSettings);
writeValues(csvWriter, rowsToGenerate);
return file;
}
开发者ID:AussieGuy0,项目名称:SDgen,代码行数:7,代码来源:CsvFactory.java
示例19: createWriter
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected CsvWriter createWriter(Writer writer, CsvWriterSettings settings) {
return new CsvWriter(writer, settings);
}
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:UniVocityCsvDataFormat.java
示例20: testMultiple2
import com.univocity.parsers.csv.CsvWriter; //导入依赖的package包/类
@Test
public void testMultiple2() {
OutputValueSwitch writerSwitch = new OutputValueSwitch("type"); //switch based on field name
writerSwitch.addSwitchForValue("SUPER", new ObjectRowWriterProcessor(), "type", "h1", "h2", "h3", "h4");
writerSwitch.addSwitchForValue("SUB1", new ObjectRowWriterProcessor(), "type", "a", "b", "c", "d", "e", "f", "g");
writerSwitch.addSwitchForValue("SUB2", new ObjectRowWriterProcessor(), "type", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
writerSwitch.addSwitchForValue("SUB3", new ObjectRowWriterProcessor(), "type", "a", "b", "c");
CsvWriterSettings settings = new CsvWriterSettings();
settings.setExpandIncompleteRows(true);
settings.getFormat().setLineSeparator("\n");
settings.setHeaderWritingEnabled(false);
settings.setRowWriterProcessor(writerSwitch);
StringWriter output = new StringWriter();
CsvWriter writer = new CsvWriter(output, settings);
writer.writeRow(newMap("SUPER", "h1=>v1;h2=>v2;h3=>v3"));
writer.writeRow(newMap("SUB1", "a=>v5;d=>v6;e=>v7;g=>v8"));
writer.writeRow(newMap("SUB2", "q=>v9;u=>v10;w=>v11;y=>v12"));
writer.writeRow(newMap("SUB1", "a=>v13;d=>v14;g=>v15"));
writer.writeRow(newMap("SUB1", "a=>v16;d=>v17;f=>v18"));
writer.writeRow(newMap("SUB3", "a=>v16;b=>v17"));
writer.writeRow(newMap("SUPER", "h1=>v1;h3=>v3"));
writer.processRecord("SUPER", "v1", null, null, "v4");
writer.processRecord("SUB1", "v1", null, null, "v4");
writer.processRecord("SUB2", "v1", null, null, "v4");
writer.processRecord("SUB3", "v1", null, null, "v4"); //v4 goes beyond the number of headers
writer.close();
assertEquals(output.toString(), "" +
"SUPER,v1,v2,v3,\n" +
"SUB1,v5,,,v6,v7,,v8\n" +
"SUB2,,v9,,,,v10,,v11,,v12,\n" +
"SUB1,v13,,,v14,,,v15\n" +
"SUB1,v16,,,v17,,v18,\n" +
"SUB3,v16,v17,\n" +
"SUPER,v1,,v3,\n" +
"SUPER,v1,,,v4\n" +
"SUB1,v1,,,v4,,,\n" +
"SUB2,v1,,,v4,,,,,,,\n" +
"SUB3,v1,,,v4\n"); //we can't lose v4
}
开发者ID:uniVocity,项目名称:univocity-parsers,代码行数:47,代码来源:Github_66.java
注:本文中的com.univocity.parsers.csv.CsvWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论