當前位置: 首頁>>代碼示例>>Java>>正文


Java CSVWriter.writeAll方法代碼示例

本文整理匯總了Java中au.com.bytecode.opencsv.CSVWriter.writeAll方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVWriter.writeAll方法的具體用法?Java CSVWriter.writeAll怎麽用?Java CSVWriter.writeAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在au.com.bytecode.opencsv.CSVWriter的用法示例。


在下文中一共展示了CSVWriter.writeAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: exportCsv

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static void exportCsv(SortedMap<Number, Number> data, String filePath) {
	try {
		writer = new CSVWriter(new FileWriter(filePath), ',', '\0');

		List<String[]> entries = new ArrayList<>(data.size());
		for (Number x : data.keySet()) {
			String xString = String.valueOf(x);
			String yString = String.valueOf(data.get(x));
			entries.add(new String[] { xString, yString });
		}

		writer.writeAll(entries);
		writer.flush();
		writer.close();
	} catch (IOException e) {
		System.err.println(e.getMessage());
	}
}
 
開發者ID:tesis-dynaware,項目名稱:fancy-chart,代碼行數:19,代碼來源:CsvDao.java

示例2: main

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
	
	CSVReader reader = new CSVReader(new FileReader(ADDRESS_FILE));
	String [] nextLine;
	while ((nextLine = reader.readNext()) != null) {
		System.out.println("Name: [" + nextLine[0] + "]\nAddress: [" + nextLine[1] + "]\nEmail: [" + nextLine[2] + "]");
	}
	
	// Try writing it back out as CSV to the console
	CSVReader reader2 = new CSVReader(new FileReader(ADDRESS_FILE));
	List allElements = reader2.readAll();
	StringWriter sw = new StringWriter();
	CSVWriter writer = new CSVWriter(sw);
	writer.writeAll(allElements);
	
	System.out.println("\n\nGenerated CSV File:\n\n");
	System.out.println(sw.toString());
	
	
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:21,代碼來源:AddressExample.java

示例3: exportToCSV

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
public void exportToCSV(File f) {
	/*
	 * Row = Series
	 * Columns = Datapoints
	 */
	try {
		/* Instantiate the CSVWriter */
		CSVWriter csvWriter = new CSVWriter(new FileWriter(f), ',',	CSVWriter.NO_QUOTE_CHARACTER);
		List<String[]> forExport = new LinkedList<String[]>();	
		
		/* Gather data */
		Map<Comparable, Collection<? extends Number>> data = getData();
		
		for (int seriesIndex=0; seriesIndex<histogramDataset.getSeriesCount(); seriesIndex++) {			
			Collection<? extends Number> datapoints = data.get(seriesIndex);			
			Collection<String> values = new LinkedList<String>();
			
			/* Add information about series */
			Comparable seriesKey = histogramDataset.getSeriesKey(seriesIndex);
			values.add(seriesKey.toString());
			
			/* Convert data */
			for (Number datapoint : datapoints) {			
				/* Add information per datapoint */
				values.add(datapoint.toString());
			}
			
			forExport.add(values.toArray(new String[values.size()]));
		}
		
		/* Write content to file */
		csvWriter.writeAll(forExport);
		csvWriter.close();
	} catch (IOException e) {
		logger.error("There was a problem with writing the file", e);
	}
}
 
開發者ID:modsim,項目名稱:vizardous,代碼行數:39,代碼來源:DistributionChart2D.java

示例4: csv

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static String csv(List<List<String>> rows) {
  StringWriter sw = new StringWriter();
  CSVWriter writer = new CSVWriter(sw);
  try {
    List<String[]> elements = new ArrayList<String[]>();
    for (List<String> row : rows) {
      elements.add(row.toArray(new String[0]));
    }
    writer.writeAll(elements);
    return sw.toString();
  } finally {
    try {
      writer.close();
    } catch (IOException e) {
      Log.exception(e);
    }
  }
}
 
開發者ID:MachinePublishers,項目名稱:ScreenSlicer,代碼行數:19,代碼來源:Spreadsheet.java

示例5: main

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static void main(String[] args)
{
	ResultSet rs = null;

	try
	{
		rs = getResultSet();
		
		StringWriter sw = new StringWriter();
		
		CSVWriter writer = new CSVWriter(sw);
		writer.writeAll(rs, false);
		writer.close();
		
		System.out.println(sw);
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}
	finally
	{
		if (rs != null)
		{
			try
			{
				rs.close();
			}
			catch (SQLException ignore)
			{
				// ignore
			}
		}
	}

}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:37,代碼來源:JdbcExample.java

示例6: write

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
 * Write a list of bean objects to csvWriter.
 * 
 * @param csvWriter
 * @param beans
 */
public static <T> void write(CSVWriter csvWriter, List<T> beans) {
    if (beans == null || beans.isEmpty()) {
        return;
    }
    Class<?> clazz = beans.get(0).getClass();
    List<Field> fields = pickFields(clazz);
    Map<String, CsvColumnInfo> orderKey2CsvColumnInfo = pickOrderKey2CsvColumnInfo(fields);

    List<String[]> list = new ArrayList<>();
    for (Object bean : beans) {
        List<String> tmp = new ArrayList<>();
        for (Entry<String, CsvColumnInfo> entry : orderKey2CsvColumnInfo.entrySet()) {
            CsvColumnInfo csvColumnInfo = entry.getValue();
            Field field = csvColumnInfo.getField();
            try {
                Object object = field.get(bean);
                String value = "";
                if (object != null) {
                    if (field.getType() == Date.class) {
                        value = csvColumnInfo.getDateFormat().format((Date) object);
                    } else {
                        value = String.valueOf(object);
                    }
                }
                tmp.add(value);
            } catch (IllegalArgumentException | IllegalAccessException e) {
                log.warn("", e);
            }
        }
        list.add(tmp.toArray(new String[tmp.size()]));
    }

    csvWriter.writeAll(list);
}
 
開發者ID:zjulzq,項目名稱:bean-csv,代碼行數:41,代碼來源:BeanCsv.java

示例7: formatToStream

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
 * Outputs a table in HTML that represents the TableModel. Only the rows
 * given will be written to the file.
 */
public void formatToStream(TableModel model, PrintWriter writer, int[] selectedRows) {
	try {
		CSVWriter csvWriter = new CSVWriter(writer);
		List<String[]> tableExport = new ArrayList<String[]>();
		int columnCount = model.getColumnCount();
		String[] rowArray = new String[columnCount];
		for (int i = 0; i < columnCount; i++) {
			rowArray[i] = model.getColumnName(i);
		}
		tableExport.add(rowArray);
		for (int row = 0; row < selectedRows.length; row++) {
			rowArray = new String[columnCount];
			for (int col = 0; col < columnCount; col++) {
				Object value = model.getValueAt(selectedRows[row], col);
				if (value != null) {
				    if (columnFormatters.get(col) != null) {
				        rowArray[col] = columnFormatters.get(col).format(value);
				    } else {
				        rowArray[col] = value.toString();
				    }
				} else {
					rowArray[col] = "";
				}
			}
			tableExport.add(rowArray);
		}
		csvWriter.writeAll(tableExport);
		csvWriter.close();

	} catch (IOException ex) {
		throw new RuntimeException("Could not close the CSV Writer", ex);
	}		
}
 
開發者ID:SQLPower,項目名稱:sqlpower-library,代碼行數:38,代碼來源:TableModelCSVFormatter.java

示例8: writeMatrix

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
private void writeMatrix(final RealMatrix m, final File outputFilename) throws IOException {
    final List<String []> textTable = new ArrayList<>();
    for (int i = 0; i < m.getRowDimension(); i ++){
        textTable.add(Arrays.stream(m.getRow(i)).mapToObj(Double::toString).toArray(String[]::new));
    }
    final FileWriter fw = new FileWriter(outputFilename);
    CSVWriter csvWriter = new CSVWriter(fw, '\t', CSVWriter.NO_QUOTE_CHARACTER);
    csvWriter.writeAll(textTable);
    csvWriter.flush();
    csvWriter.close();
}
 
開發者ID:broadinstitute,項目名稱:gatk-protected,代碼行數:12,代碼來源:DecomposeSingularValues.java

示例9: doCommit

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
/**
 * This is where all of the writing to the file gets done.
 * So rollback does nothing, which is correct.
 */
@Override
public void doCommit() throws Exception {
	FileWriter writer = new FileWriter(new File(getFilePath()),
			!getClearFile());
	
	csvWriter = new CSVWriter(writer, getSeparator(), getQuoteChar(),
			getEscapeChar());
	csvWriter.writeAll(contents);
	csvWriter.close();
}
 
開發者ID:SQLPower,項目名稱:power-matchmaker,代碼行數:15,代碼來源:CSVWriterMungeStep.java

示例10: getCsvResults

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
private String getCsvResults(List<Map<String, Object>> rows) {
    List<String[]> outputRows = new ArrayList<String[]>();
    Boolean first = true;

    StringWriter stringWriter = new StringWriter();
    CSVWriter csvWriter = new CSVWriter(stringWriter);

    for (Map<String, Object> row : rows) {
        if (first) {
            Set<String> keys = row.keySet();
            String[] columnTitles = new String[keys.size()];
            columnTitles = keys.toArray(columnTitles);
            outputRows.add(columnTitles);
            first = false;
        }

        Collection<Object> values = row.values();
        Object[] columnValues = new Object[values.size()];
        columnValues = values.toArray(columnValues);

        Integer numberOfValues = values.size();
        String[] columnOutputValues = new String[numberOfValues];
        for (int i = 0; i < numberOfValues; i++) {
            Object columnValue = columnValues[i];
            if (columnValue != null) {
              columnOutputValues[i] = columnValue.toString();
            } else {
              columnOutputValues[i] = "";
            }
        }
        outputRows.add(columnOutputValues);
    }

    csvWriter.writeAll(outputRows);

    return stringWriter.toString();
}
 
開發者ID:BjoernKW,項目名稱:ZenQuery,代碼行數:38,代碼來源:ResultSetController.java

示例11: toString

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public String toString() {
	StringWriter output = new StringWriter();
	CSVWriter writer = new CSVWriter(output, ',');
	try {
		writer.writeAll(toArray());
		writer.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return output.toString();
}
 
開發者ID:mfit,項目名稱:PdfTableAnnotator,代碼行數:12,代碼來源:CsvExport.java

示例12: exportToCSV

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
public void exportToCSV(File f) {
	/*
	 * Row = Cell ID XX
	 * Column = Timepoint
	 */
	try {
		/* Instantiate the CSVWriter */
		CSVWriter csvWriter = new CSVWriter(new FileWriter(f), ',',	CSVWriter.NO_QUOTE_CHARACTER);

		List<String[]> forExport = new LinkedList<String[]>();

		/* Generate header */
		List<String> header = new ArrayList<String>();
		header.add("Time");
		for (int seriesIndex=0; seriesIndex<this.dataset.getSeriesCount(); seriesIndex++) {
			Comparable seriesKey = this.dataset.getSeriesKey(seriesIndex);
			
			if (seriesKey instanceof String) {					
				header.add((String) seriesKey);
			}
		}
		forExport.add((String[]) header.toArray(new String[header.size()]));

		// Keep track of the timepoints
		Set<Double> timepoints = new TreeSet<Double>();			
		
		/* Gather data */
		Map<Integer, Map<Double, Double>> data = new TreeMap<Integer, Map<Double, Double>>();
		
		for (int seriesIndex=0; seriesIndex<this.dataset.getSeriesCount(); seriesIndex++) {			
			Map<Double, Double> seriesMap = new TreeMap<Double, Double>();
			
			for (int i=0; i<this.dataset.getItemCount(seriesIndex); i++) {				
				Number x = this.dataset.getX(seriesIndex, i);
				Number y = this.dataset.getY(seriesIndex, i);
				
				seriesMap.put(x.doubleValue(), y.doubleValue());
				timepoints.add(x.doubleValue());
			}
			
			data.put(seriesIndex, seriesMap);
		}
			
		/* Convert data */
		for (Double timepoint : timepoints) {
			String[] values = new String[data.size()+1];
			
			/* Add information about timepoint */
			values[0] = timepoint.toString();
			
			/* Add information per timepoint */
			for(int seriesIndex=0; seriesIndex<data.size(); seriesIndex++) {
				Map<Double, Double> seriesData = data.get(seriesIndex);
				Double value = seriesData.get(timepoint);
				
				if (value != null) {
					values[seriesIndex+1] = value.toString(); // Index shift because of time column
				} else {
					values[seriesIndex+1] = ""; // Index shift because of time column
				}
			}
				
			forExport.add(values);
		}
		
		/* Write content to file */
		csvWriter.writeAll(forExport);
		csvWriter.close();
	} catch (IOException e) {
		logger.error("There was a problem with writing the file", e);
	}
}
 
開發者ID:modsim,項目名稱:vizardous,代碼行數:74,代碼來源:TraceChart2D.java

示例13: run

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
protected IStatus run(IProgressMonitor monitor) {
	try {
		TimedSeries<String, Double> sereis = new TimedSeries<String, Double>();
		Range xRange = xyGraph.primaryXAxis.getRange();
		long lower = (long) xRange.getLower();
		long upper = (long) xRange.getUpper();
		List<Trace> traceList = xyGraph.getPlotArea().getTraceList();
		List<String> titleValues = new ArrayList<String>();
		titleValues.add("Time");
		for (Trace t : traceList) {
			titleValues.add(t.getName());
			CircularBufferDataProvider provider = (CircularBufferDataProvider) t.getDataProvider();
			for (int inx = 0; inx < provider.getSize(); inx++) {
				Sample sample = (Sample) provider.getSample(inx);
				double x = sample.getXValue();
				if(x < lower || x > upper) {
					continue;
				}
				double y = sample.getYValue();
				sereis.add(t.getName(), (long)x, y);
			}
		}
		List<String[]> values = new ArrayList<String[]>();
		values.add(titleValues.toArray(new String[titleValues.size()]));
		while (lower < upper) {
			List<String> value = new ArrayList<String>();
			value.add(DateUtil.format(lower, "yyyy-MM-dd HH:mm"));
			for (int i = 1; i < titleValues.size(); i++) {
				String objName = titleValues.get(i);
				Double d = sereis.getInTime(objName, lower, DateUtil.MILLIS_PER_FIVE_MINUTE - 1);
				if (d != null) {
					value.add(FormatUtil.print(d.doubleValue(), "#,###.##"));
				} else {
					value.add("");
				}
			}
			values.add(value.toArray(new String[value.size()]));
			lower += DateUtil.MILLIS_PER_FIVE_MINUTE;
		}
		CSVWriter cw = new CSVWriter(new FileWriter(filePath));
		cw.writeAll(values);
		cw.flush();
		cw.close();
	} catch (Exception e) {
		e.printStackTrace();
		return Status.CANCEL_STATUS;
	}
	return Status.OK_STATUS;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:51,代碼來源:CounterPastLongDateAllView.java

示例14: run

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
@Override
protected IStatus run(IProgressMonitor monitor) {
	try {
		TimedSeries<String, Double> sereis = new TimedSeries<String, Double>();
		Range xRange = xyGraph.primaryXAxis.getRange();
		long lower = (long) xRange.getLower();
		long upper = (long) xRange.getUpper();
		List<Trace> traceList = xyGraph.getPlotArea().getTraceList();
		List<String> titleValues = new ArrayList<String>();
		titleValues.add("Time");
		for (Trace t : traceList) {
			titleValues.add(t.getName());
			CircularBufferDataProvider provider = (CircularBufferDataProvider) t.getDataProvider();
			for (int inx = 0; inx < provider.getSize(); inx++) {
				Sample sample = (Sample) provider.getSample(inx);
				double x = sample.getXValue();
				if(x < lower || x > upper) {
					continue;
				}
				double y = sample.getYValue();
				sereis.add(t.getName(), (long)x, y);
			}
		}
		List<String[]> values = new ArrayList<String[]>();
		values.add(titleValues.toArray(new String[titleValues.size()]));
		while (lower < upper) {
			List<String> value = new ArrayList<String>();
			value.add(DateUtil.format(lower, "HH:mm:ss"));
			for (int i = 1; i < titleValues.size(); i++) {
				String objName = titleValues.get(i);
				Double d = sereis.getInTime(objName, lower, 3000);
				if (d != null) {
					value.add(FormatUtil.print(d.doubleValue(), "#,###.##"));
				} else {
					value.add("");
				}
			}
			values.add(value.toArray(new String[value.size()]));
			lower += 2000;
		}
		CSVWriter cw = new CSVWriter(new FileWriter(filePath));
		cw.writeAll(values);
		cw.flush();
		cw.close();
	} catch (Exception e) {
		e.printStackTrace();
		return Status.CANCEL_STATUS;
	}
	return Status.OK_STATUS;
}
 
開發者ID:scouter-project,項目名稱:scouter,代碼行數:51,代碼來源:CounterPastTimeAllView.java

示例15: main

import au.com.bytecode.opencsv.CSVWriter; //導入方法依賴的package包/類
public static void main(final String[] args) throws IOException, URISyntaxException {
    final CSVWriter csvWriter = new CSVWriter(new FileWriter(MANIFESTS_CSV));
    final JsonObject source = new JsonObject(StringUtils.read(new File(SOURCE)));
    final JsonArray jsonCanvases = source.getJsonArray("sequences").getJsonObject(0).getJsonArray("canvases");
    final String objID = source.getString("label"); // object ARK
    final List<String[]> csvData = new ArrayList<String[]>();

    for (int index = 0; index < jsonCanvases.size(); index++) {
        final JsonObject jsonCanvas = jsonCanvases.getJsonObject(index);
        final String label = jsonCanvas.getString("label");
        final JsonArray images = jsonCanvas.getJsonArray("images");
        final String thumbnail = jsonCanvas.getString("thumbnail");
        final String id = objID + "/" + label;
        final Manifest manifest = getManifest(id, label, thumbnail);
        final Sequence sequence = getSequence(id, label, 1);
        final List<Canvas> canvases = new ArrayList<Canvas>();

        csvData.add(new String[] { id, label });

        for (int imgIndex = 0; imgIndex < images.size(); imgIndex++) {
            final JsonObject jsonImage = images.getJsonObject(imgIndex);
            final JsonObject jsonResource = jsonImage.getJsonObject("resource");
            final int width = jsonResource.getInteger("width").intValue();
            final int height = jsonResource.getInteger("height").intValue();
            final JsonObject jsonService = jsonResource.getJsonObject("service");
            final String serviceLabel = jsonService.getString("label");
            // Fix for bad master manifests -- shouldn't contain info.json in service ID
            final String serviceId = jsonService.getString("@id").replace("/info.json", "");
            final Canvas canvas = getCanvas(id, serviceLabel, imgIndex + 1, width, height);
            final String imageId = getID(IIIF_SERVER, PathUtils.encodeIdentifier(id), "imageanno", 1);
            final Image image = new Image(imageId);
            final ImageResource resource = new ImageResource();
            final Service service = new Service(serviceId);

            image.setOn(canvas.getId());
            service.setProfile(IIIF_PROFILE);
            service.setContext(IIIF_CONTEXT);
            service.setLabel(canvas.getLabel());
            resource.setHeight(height);
            resource.setWidth(width);
            resource.setFormat("image/jpeg");
            resource.setService(service);
            image.setResource(resource);
            canvas.setImages(Arrays.asList(new Image[] { image }));

            if (!serviceLabel.endsWith("_color")) {
                canvas.setThumbnail(getThumbnail(getBareID(serviceId)));
                canvases.add(canvas);
            }
        }

        sequence.setCanvases(canvases);
        manifest.setSequences(Arrays.asList(new Sequence[] { sequence }));

        final String path = StringUtils.format(MANIFEST_PATH, label);
        final FileWriter writer = new FileWriter(new File(path));

        writer.write(toJson(manifest));
        writer.close();
    }

    csvWriter.writeAll(csvData);
    csvWriter.close();
}
 
開發者ID:UCLALibrary,項目名稱:ezid-crawler,代碼行數:65,代碼來源:Submanifestor.java


注:本文中的au.com.bytecode.opencsv.CSVWriter.writeAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。