本文整理汇总了Java中com.opencsv.CSVWriter.writeNext方法的典型用法代码示例。如果您正苦于以下问题:Java CSVWriter.writeNext方法的具体用法?Java CSVWriter.writeNext怎么用?Java CSVWriter.writeNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.opencsv.CSVWriter
的用法示例。
在下文中一共展示了CSVWriter.writeNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHttpSourcesExportStream
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public static StreamResource getHttpSourcesExportStream() {
StreamResource.StreamSource source = (StreamResource.StreamSource) () -> {
LOG.info("Exporting http sources data...");
List<HttpSource> sources = ElasticSearch.getHttpSourceOperations().all();
StringWriter writer = new StringWriter();
CSVWriter csvWriter = CSVUtils.createDefaultWriter(writer);
// Header line creation
csvWriter.writeNext(CSV_COLUMNS);
for (HttpSource ld : sources) {
csvWriter.writeNext(mapHttpSourceToCsvRow(ld));
}
String csv = writer.getBuffer().toString();
return new ByteArrayInputStream(csv.getBytes(Charsets.UTF_8));
};
return new StreamResource(source, "http-sources-exported-" +
new SimpleDateFormat("yyyyMMdd").format(new Date()) + ".csv");
}
示例2: build
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public static File build(Long examId, Collection<Long> childIds) throws IOException {
List<ExamRecord> examRecords = Ebean.find(ExamRecord.class)
.fetch("examScore")
.where()
.eq("exam.parent.id", examId)
.in("exam.id", childIds)
.findList();
File file = File.createTempFile("csv-output-", ".tmp");
CSVWriter writer = new CSVWriter(new FileWriter(file));
writer.writeNext(ExamScore.getHeaders());
for (ExamRecord record : examRecords) {
writer.writeNext(record.getExamScore().asArray(record.getStudent(), record.getTeacher(), record.getExam()));
}
writer.close();
return file;
}
示例3: writeStopTimes
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
/**
* Experimental class to write stop_times.txt from a (filtered) collection of trips. stop_times.txt is
* usually the largest file.
*/
public static void writeStopTimes(Collection<Trip> trips, String folder) throws IOException {
CSVWriter stopTimesWriter = new CSVWriter(new FileWriter(folder + GtfsDefinitions.Files.STOP_TIMES.fileName), ',');
String[] header = GtfsDefinitions.Files.STOP_TIMES.columns;
stopTimesWriter.writeNext(header, true);
for(Trip trip : trips) {
for(StopTime stopTime : trip.getStopTimes()) {
// TRIP_ID, STOP_SEQUENCE, ARRIVAL_TIME, DEPARTURE_TIME, STOP_ID
String[] line = new String[header.length];
line[0] = stopTime.getTrip().getId();
line[1] = String.valueOf(stopTime.getSequencePosition());
line[2] = Time.writeTime(stopTime.getArrivalTime());
line[3] = Time.writeTime(stopTime.getDepartureTime());
line[4] = stopTime.getStop().getId();
stopTimesWriter.writeNext(line);
}
}
stopTimesWriter.close();
}
示例4: merge
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
private synchronized void merge(List<File> inputFiles, File outputFile) throws IOException {
AttributeSetCollector collector = null;
CSVWriter writer = null;
try {
collector = new AttributeSetCollector(inputFiles);
writer = FileUtil.createWriter(outputFile);
while (collector.hasNext()) {
String[] nextList = collector.nextValue2AttSet();
writer.writeNext(nextList);
}
} finally {
if (collector != null) {
collector.close();
}
if (writer != null) {
writer.close();
}
}
}
示例5: getNamedQueriesExportStream
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public static StreamResource getNamedQueriesExportStream() {
StreamResource.StreamSource source = (StreamResource.StreamSource) () -> {
LOG.info("Exporting http sources data...");
List<NamedQuery> namedQueries = ElasticSearch.getNamedQueryOperations().all();
StringWriter writer = new StringWriter();
CSVWriter csvWriter = CSVUtils.createDefaultWriter(writer);
csvWriter.writeNext(CSV_COLUMNS);
for (NamedQuery nq : namedQueries) {
csvWriter.writeNext(new String[]{
nq.getName(),
nq.getNotStemmedCaseSensitive(),
nq.getNotStemmedCaseInSensitive(),
nq.getStemmedCaseSensitive(),
nq.getStemmedCaseInSensitive(),
nq.getAdvanced()
});
}
String csv = writer.getBuffer().toString();
return new ByteArrayInputStream(csv.getBytes(Charsets.UTF_8));
};
return new StreamResource(source, "named-queries-exported-" +
new SimpleDateFormat("yyyyMMdd").format(new Date()) + ".csv");
}
示例6: getHttpSourcesExportStream
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public static StreamResource getHttpSourcesExportStream() {
StreamResource.StreamSource source = (StreamResource.StreamSource) () -> {
LOG.info("Exporting http sources data...");
List<HttpSourceTest> tests = ElasticSearch.getHttpSourceTestOperations().all();
StringWriter writer = new StringWriter();
CSVWriter csvWriter = CSVUtils.createDefaultWriter(writer);
// Header line creation
csvWriter.writeNext(CSV_COLUMNS);
for (HttpSourceTest hst : tests) {
csvWriter.writeNext(mapHttpSourceTestToCsvRow(hst));
}
String csv = writer.getBuffer().toString();
return new ByteArrayInputStream(csv.getBytes(Charsets.UTF_8));
};
return new StreamResource(source, "http-source-tests-exported-" +
new SimpleDateFormat("yyyyMMdd").format(new Date()) + ".csv");
}
示例7: writeStops
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
/**
* Experimental class to write stops.txt (i.e. after filtering for one date)
*/
public static void writeStops(Collection<Stop> stops, String folder) throws IOException {
CSVWriter stopsWriter = new CSVWriter(new FileWriter(folder + GtfsDefinitions.Files.STOPS.fileName), ',');
String[] header = GtfsDefinitions.Files.STOPS.columns;
stopsWriter.writeNext(header, true);
for(Stop stop : stops) {
// STOP_ID, STOP_LON, STOP_LAT, STOP_NAME
String[] line = new String[header.length];
line[0] = stop.getId();
line[1] = String.valueOf(stop.getLon());
line[2] = String.valueOf(stop.getLat());
line[3] = stop.getName();
stopsWriter.writeNext(line);
}
stopsWriter.close();
}
示例8: processCsv
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
private String processCsv(TableModel model, Writer dest) throws IOException {
CSVWriter writer = new CSVWriter(dest, DELIMITER, QUOTE);
try {
String[] row = new String[model.getColumnCount()];
for (int j = 0; j < model.getColumnCount(); j++)
row[j] = model.getColumnName(j);
writer.writeNext(row);
for (int i = 0; i < model.getRowCount(); i++) {
for (int j = 0; j < model.getColumnCount(); j++)
row[j] = (String) model.getValueAt(i, j);
writer.writeNext(row);
}
writer.flush();
return (String.format("Exported %d rows", model.getRowCount()));
} finally {
writer.close();
}
}
示例9: encode
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
/**
* Used to encode the request content using the OpenCsv writer.
*
* @param config the configuration
* @param ts the server request content accessor
*/
public static void encode(final ChainedHttpConfig config, final ToServer ts) {
if (handleRawUpload(config, ts)) {
return;
}
final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest();
final Csv.Context ctx = (Csv.Context) config.actualContext(request.actualContentType(), Csv.Context.ID);
final Object body = checkNull(request.actualBody());
checkTypes(body, new Class[]{Iterable.class});
final StringWriter writer = new StringWriter();
final CSVWriter csvWriter = ctx.makeWriter(new StringWriter());
Iterable<?> iterable = (Iterable<?>) body;
for (Object o : iterable) {
csvWriter.writeNext((String[]) o);
}
ts.toServer(stringToStream(writer.toString(), request.actualCharset()));
}
示例10: exportTrajectoryDataAsCSV
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public void exportTrajectoryDataAsCSV(ArrayList<? extends Trajectory> tracks, String path){
String[] nextLine = null;
try {
CSVWriter writer = new CSVWriter(new FileWriter(path, false), ',');
nextLine = new String[]{"ID","X","Y","CLASS"};
writer.writeNext(nextLine);
for(int i = 0; i < tracks.size(); i++){
Trajectory t = tracks.get(i);
for(int j = 0; j < t.size(); j++){
nextLine = new String[]{""+t.getID(),""+t.get(j).x,""+t.get(j).y,t.getType()};
writer.writeNext(nextLine);
}
}
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例11: saveProductsToCsv
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public static void saveProductsToCsv(HashMap<String, List<String>> cache) {
try {
File file = new File(CSV_PATH);
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
CSVWriter csvWriter = new CSVWriter(new FileWriter(CSV_PATH));
for (Map.Entry<String, List<String>> entry : cache.entrySet()) {
String key = entry.getKey();
for (String item : entry.getValue()) {
csvWriter.writeNext(new String[]{key, item});
}
}
csvWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例12: initialise
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
@Override
public void initialise() throws IOException {
// Create the parent dirs
new File(csvFilename).getAbsoluteFile().getParentFile().mkdirs();
writer = new CSVWriter(new FileWriter(csvFilename, false), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
// Print the header
writer.writeNext(new String[] {
"Type",
"Subtype",
"Source type",
"Target type",
"Lemma",
"Lemma POS",
"Alternatives...."
});
}
示例13: write
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
private void write(CSVWriter writer, Entry entry, Level level, LoadRecord loadRecord) {
String[] record = new String[RegionLoadAdapter.loadEntries.length + 2];
if (entry == Entry.header) {
record[0] = load.getLevelClass().getLevelTypeString();
record[1] = HEADER_TIMESTAMP;
} else {
record[0] = level.toString();
record[1] = String.valueOf(load.getTimestampIteration());
}
for (LoadEntry loadEntry : RegionLoadAdapter.loadEntries) {
if (entry == Entry.header) {
record[RegionLoadAdapter.loadEntryOrdinal(loadEntry) + 2] = loadEntry.name();
} else {
Number number = loadRecord.get(loadEntry);
record[RegionLoadAdapter.loadEntryOrdinal(loadEntry) + 2] = number == null ? "" : number.toString();
}
}
writer.writeNext(record);
}
示例14: writeCSVFile
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public XmlDocMaker writeCSVFile(Collection<Element> elements,
char delimiter, boolean xpathOutput, Collection<String> xpaths,
Outputs out) throws Throwable {
XmlDocMaker doc = new XmlDocMaker("nbResults");
File of = PluginService.createTemporaryFile();
CSVWriter csvWriter = new CSVWriter(new OutputStreamWriter(
new BufferedOutputStream(new FileOutputStream(of, true))),
delimiter, '"');
int count = 0;
Collection<String[]> table = createContentTable(elements, delimiter, xpathOutput, xpaths, out);
if (table != null){
count = table.size() -1;
Iterator<String[]> tableInt = table.iterator();
while (tableInt.hasNext()){
csvWriter.writeNext(tableInt.next());
}
}else{
String [] fail = new String [] {"No Matched results for queried elements!"};
csvWriter.writeNext(fail);
}
doc.add("count", Integer.toString(count));
csvWriter.close();
PluginService.Output output = out.output(0);
output.setData(new TempFileInputStream(of), of.length(), "plain/text");
return doc;
}
示例15: save
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
@Override
public boolean save(String file) {
try {
File f = new File(Login.getUser().getUserFolder() + File.separator
+ file + DataDudeFile.T_CSV);
f.createNewFile();
CSVWriter w = new CSVWriter(new FileWriter(f), ',',
CSVWriter.DEFAULT_QUOTE_CHARACTER,
CSVWriter.DEFAULT_ESCAPE_CHARACTER,
System.getProperty("line.separator"));
// Write It Out
for (int i = 0; i < lines.length; i++)
if (!(lines[i].getText().isEmpty())) // Make sure it isn't empty
w.writeNext(lines[i].getText().split("\\s*,\\s*"), false);
w.close();
} catch (Exception e) {
String text = "Exception while trying to save file:\n"
+ e.getMessage();
DataDude.showError(this, e, text);
return false;
}
return true;
}