当前位置: 首页>>代码示例>>Java>>正文


Java CSVWriter.writeNext方法代码示例

本文整理汇总了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");
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:19,代码来源:HttpSourceImportExport.java

示例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;
    }
 
开发者ID:CSCfi,项目名称:exam,代码行数:19,代码来源:CsvBuilder.java

示例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();
}
 
开发者ID:matsim-org,项目名称:pt2matsim,代码行数:25,代码来源:GtfsTools.java

示例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();
    }
  }
}
 
开发者ID:HPI-Information-Systems,项目名称:AdvancedDataProfilingSeminar,代码行数:20,代码来源:Merger.java

示例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");
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:25,代码来源:NamedQueryImportExport.java

示例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");
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:19,代码来源:HttpSourceTestImportExport.java

示例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();
}
 
开发者ID:matsim-org,项目名称:pt2matsim,代码行数:19,代码来源:GtfsTools.java

示例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();
	}

}
 
开发者ID:curiosag,项目名称:ftc,代码行数:24,代码来源:CSV.java

示例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()));
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:26,代码来源:Csv.java

示例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();
	}
}
 
开发者ID:thorstenwagner,项目名称:ij-trajectory-classifier,代码行数:22,代码来源:ExportImportTools.java

示例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();
    }
}
 
开发者ID:andretf,项目名称:batatas-android,代码行数:23,代码来源:Utils.java

示例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...."
	});
}
 
开发者ID:dstl,项目名称:baleen,代码行数:19,代码来源:CsvInteractionWriter.java

示例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);
}
 
开发者ID:kakao,项目名称:hbase-tools,代码行数:20,代码来源:LoadIO.java

示例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;
}
 
开发者ID:uom-daris,项目名称:daris,代码行数:27,代码来源:SvcObjectCSVExport.java

示例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;
}
 
开发者ID:realAhmedRoach,项目名称:DataDude,代码行数:26,代码来源:CSVNode.java


注:本文中的com.opencsv.CSVWriter.writeNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。