本文整理匯總了Java中au.com.bytecode.opencsv.CSVWriter.writeNext方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVWriter.writeNext方法的具體用法?Java CSVWriter.writeNext怎麽用?Java CSVWriter.writeNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類au.com.bytecode.opencsv.CSVWriter
的用法示例。
在下文中一共展示了CSVWriter.writeNext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeCSV
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
* Writes the data set to a CSV file
*
* @param file
* @param dataset
* @throws IOException
*/
public void writeCSV(File file, DataSet<RecordType, SchemaElementType> dataset)
throws IOException {
CSVWriter writer = new CSVWriter(new FileWriter(file));
String[] headers = getHeader(dataset);
if(headers!=null) {
writer.writeNext(headers);
}
for (RecordType record : dataset.get()) {
String[] values = format(record, dataset);
writer.writeNext(values);
}
writer.close();
}
示例2: csv
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
* Dump out a VoltTable as a CSV to the given writer
* If the header flag is set to true, then the output will include
* the column names in the first row
* @param out
* @param vt
* @param write_header
*/
public static void csv(Writer out, VoltTable vt, boolean header) {
CSVWriter writer = new CSVWriter(out);
if (header) {
String cols[] = new String[vt.getColumnCount()];
for (int i = 0; i < cols.length; i++) {
cols[i] = vt.getColumnName(i);
} // FOR
writer.writeNext(cols);
}
vt.resetRowPosition();
while (vt.advanceRow()) {
String row[] = vt.getRowStringArray();
assert(row != null);
assert(row.length == vt.getColumnCount());
writer.writeNext(row);
} // WHILE
}
示例3: exportDatabaseToCsvString
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public synchronized String exportDatabaseToCsvString() {
StringWriter stringWriter = new StringWriter();
CSVWriter csvWriter = new CSVWriter(stringWriter);
csvWriter.writeNext(ThreeThingsEntry.COLUMNS);
SQLiteDatabase db = mDbHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + ThreeThingsEntry.TABLE_NAME, null);
while (cursor.moveToNext()) {
List<String> data = new ArrayList(ThreeThingsEntry.COLUMNS.length);
for (String column : ThreeThingsEntry.COLUMNS) {
data.add(cursor.getString(cursor.getColumnIndexOrThrow(column)));
}
csvWriter.writeNext(data.toArray(new String[0]));
}
try {
csvWriter.close();
} catch (IOException e) {
// Ignore.
}
return stringWriter.toString();
}
示例4: writeCSVfile
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
* Writes newly calculated and equally distributed vector data to user specified CSV file.
*
* @param list finalized vector data to write to user specified output file
*/
public static void writeCSVfile(List<List<String>> list) {
String outputFile = myResultDir;
boolean alreadyExists = new File(outputFile).exists();
try {
CSVWriter csvOutput = new CSVWriter(new FileWriter(outputFile), ','); // Create new instance of CSVWriter to write to file output
if (!alreadyExists) {
csvOutput.writeNext(myHeader); // Write the text headers first before data
for (int i = 0; i < list.size(); i++) // Iterate through all rows in 2D array
{
String[] temp = new String[list.get(i).size()]; // Convert row array list in 2D array to regular string array
temp = list.get(i).toArray(temp);
csvOutput.writeNext(temp); // Write this array to the file
}
}
csvOutput.close(); // Close csvWriter
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: writeCSV
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
* Writes the data set to a CSV file
*
* @param file
* @param dataset
* @throws IOException
*/
public void writeCSV(File file, Processable<RecordType> dataset)
throws IOException {
CSVWriter writer = new CSVWriter(new FileWriter(file));
String[] headers = getHeader();
if(headers!=null) {
writer.writeNext(headers);
}
for (RecordType record : dataset.get()) {
String[] values = format(record);
writer.writeNext(values);
}
writer.close();
}
示例6: writeSimpleWeightedGraph2CSV
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static void writeSimpleWeightedGraph2CSV(SimpleWeightedGraph<Long, DefaultWeightedEdge> colocationgraph,
File file) throws IOException {
CSVWriter writer = new CSVWriter(new FileWriter(file), ';');
// write header
String[] line = new String[4];
line[0] = "source";
line[1] = "target";
line[2] = "weight";
line[3] = "type";
writer.writeNext(line);
for (DefaultWeightedEdge e : colocationgraph.edgeSet()) {
line = new String[4];
line[0] = String.valueOf(colocationgraph.getEdgeSource(e).longValue() + (long) 111);
line[1] = String.valueOf(colocationgraph.getEdgeTarget(e).longValue() + (long) 111);
line[2] = String.valueOf(colocationgraph.getEdgeWeight(e));
line[3] = "undirected";
writer.writeNext(line);
}
writer.close();
}
示例7: testWrite
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Test
public void testWrite() throws IOException {
String[] row1 = new String[] { "oneone", "onetwo", "onethree" };
String[] row2 = new String[] { "twoone", "twotwo", "twothree" };
StringWriter sWriter = new StringWriter();
CSVWriter writer = new CSVWriter(sWriter, ',', '\'');
writer.writeNext(row1);
writer.writeNext(row2);
String written = sWriter.toString();
CSVReader reader = new CSVReader(new StringReader(written), ',', '\'');
List<String[]> rows = reader.readAll();
assertTrue(Arrays.equals(rows.get(0), row1));
assertTrue(Arrays.equals(rows.get(1), row2));
}
示例8: getCustomerExportEmails
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@GET
@Path("export/emails")
// @Produces("text/plain")
public Response getCustomerExportEmails(@FilterParam Filter filter, @Context HttpServletResponse response)
throws IOException {
response.setContentType("text/csv");
response.setHeader("Content-Disposition", "attachment; filename=\"customer-emails.csv\"");
PrintWriter printWriter = response.getWriter();
CSVWriter writer = new CSVWriter(printWriter, ';');
writer.writeNext(new String[] { "E-mail" });
List<Customer> customers = service.get(Customer.class);
for (Customer customer : customers) {
if (customer.getEmail() != null && !customer.getEmail().isEmpty()) {
writer.writeNext(new String[] { customer.getEmail() });
}
}
writer.flush();
writer.close();
return Response.ok().build();
}
示例9: dumpSecurityStructure
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
private void dumpSecurityStructure(CSVWriter csvWriter, String securityType, ManageableSecurity firstSecurity) {
if (firstSecurity == null) {
s_logger.error("null security passed to dumpSecurityStructure");
return;
}
s_logger.info("Processing security " + firstSecurity);
csvWriter.writeNext(new String[] {securityType });
csvWriter.writeNext(new String[] {firstSecurity.metaBean().beanName() });
csvWriter.writeNext(new String[] {"Type", "Name", "Example"});
Iterable<MetaProperty<?>> metaPropertyIterable = firstSecurity.metaBean().metaPropertyIterable();
for (MetaProperty<?> metaProperty : metaPropertyIterable) {
s_logger.info("Field" + metaProperty.name());
String strValue;
try {
strValue = metaProperty.getString(firstSecurity);
} catch (IllegalStateException ise) {
strValue = metaProperty.get(firstSecurity).toString();
}
csvWriter.writeNext(new String[] {metaProperty.propertyType().getSimpleName(), metaProperty.name(), strValue });
}
csvWriter.writeNext(new String[] {});
}
示例10: CsvSheetWriter
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public CsvSheetWriter(String filename, String[] columns) {
ArgumentChecker.notEmpty(filename, "filename");
ArgumentChecker.notNull(columns, "columns");
// Open file
OutputStream fileOutputStream = openFile(filename);
// Set up CSV Writer
_csvWriter = new CSVWriter(new OutputStreamWriter(fileOutputStream));
// Set columns
setColumns(columns);
// Write the column row
_csvWriter.writeNext(columns);
flush();
}
示例11: writeInternal
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
protected void writeInternal(QuoteWrapper quotes, HttpOutputMessage httpOutputMessage) throws IOException, HttpMessageNotWritableException {
CSVWriter writer = new CSVWriter(new OutputStreamWriter(httpOutputMessage.getBody()));
for (YahooQuote quote : quotes) {
writer.writeNext(
new String[]{ quote.getId(),
quote.getName(),
String.valueOf(quote.getOpen()),
String.valueOf(quote.getPreviousClose()),
String.valueOf(quote.getLast()),
String.valueOf(quote.getLastChange()),
String.valueOf(quote.getLastChangePercent()),
String.valueOf(quote.getHigh()),
String.valueOf(quote.getLow()),
String.valueOf(quote.getBid()),
String.valueOf(quote.getAsk()),
String.valueOf(quote.getVolume()),
quote.getExchange(),
quote.getCurrency()
});
}
writer.close();
}
示例12: performFinish
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
public boolean performFinish() {
try {
CSVWriter writer = new CSVWriter(new FileWriter(new File(FileHandler.getCFGFilePath("regex.csv"))), ';');
writer.writeNext(new String[] {"Name","Regex"});
for (Regex r : CombineNodesCommand.getRegex()) {
if (!r.getName().isEmpty())
writer.writeNext(new String[] {r.getName(),r.getRegex().replaceAll("\\\\", "\\\\\\\\"), r.getTable()});
}
writer.flush();
writer.close();
// MyOntologyTrees.createRegexMenu();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
示例13: writeCSV
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public void writeCSV(File file) throws IOException {
FileWriter writer = new FileWriter(file);
CSVWriter csvWriter = new CSVWriter(writer);
for (QueryLogValue query : queryLogStatistic.getLastQueries()) {
String[] cols = new String[] {
String.valueOf(query.isError()),
query.getQueryString(),
query.getFacetQueryString(),
query.getFilterQueryString(),
query.getQTime().toString(),
query.getResults().toString()
};
csvWriter.writeNext(cols);
}
csvWriter.close();
}
示例14: write
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public boolean write(MappingStrategy<T> mapper, CSVWriter csv,
List<?> objects) {
if (objects == null || objects.isEmpty())
return false;
try {
csv.writeNext(processHeader(mapper));
List<Method> getters = findGetters(mapper);
for (Object obj : objects) {
String[] line = processObject(getters, obj);
csv.writeNext(line);
}
return true;
} catch (Exception e) {
throw new RuntimeException("Error writing CSV !", e);
}
}
示例15: write
import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
public void write(CSVWriter csvWriter, List<Player> models) {
csvWriter.writeNext(new String[]{
"id",
"birthDate",
"region",
"country",
"gender",
"externalId",
"customData"
});
for(Player model : models) {
csvWriter.writeNext(new String[]{
model.getId().toString(),
CsvHelper.formatDate(model.getBirthDate()),
model.getRegion(),
model.getCountry(),
model.getGender() != null ? model.getGender().name() : null,
model.getExternalId(),
model.getCustomData()
});
}
}