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


Java CsvListWriter类代码示例

本文整理汇总了Java中org.supercsv.io.CsvListWriter的典型用法代码示例。如果您正苦于以下问题:Java CsvListWriter类的具体用法?Java CsvListWriter怎么用?Java CsvListWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CsvListWriter类属于org.supercsv.io包,在下文中一共展示了CsvListWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: flushTriples

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
public static InputStream flushTriples(Iterable<KiWiTriple> tripleBacklog) throws IOException {
    StringWriter out = new StringWriter();
    CsvListWriter writer = new CsvListWriter(out, CsvPreference.STANDARD_PREFERENCE);

    // reuse the same array to avoid unnecessary object allocation
    Object[] rowArray = new Object[10];
    List<Object> row = Arrays.asList(rowArray);

    for(KiWiTriple t : tripleBacklog) {
        rowArray[0] = t.getId();
        rowArray[1] = t.getSubject();
        rowArray[2] = t.getPredicate();
        rowArray[3] = t.getObject();
        rowArray[4] = t.getContext();
        rowArray[5] = t.getCreator();
        rowArray[6] = t.isInferred();
        rowArray[7] = t.isDeleted();
        rowArray[8] = t.getCreated();
        rowArray[9] = t.getDeletedAt();

        writer.write(row, tripleProcessors);
    }
    writer.close();

    return IOUtils.toInputStream(out.toString());
}
 
开发者ID:apache,项目名称:marmotta,代码行数:27,代码来源:MySQLLoadUtil.java

示例2: exportAll

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
@Override
public boolean exportAll(final Path file) {

    try {
        listWriter = new CsvListWriter(new FileWriter(file.toFile()), CsvPreference.STANDARD_PREFERENCE);

        // write the header
        listWriter.writeHeader(config.getHeaders());

        writeAnimeList();
        writeWatchList();
        writeFilterList();

        listWriter.close();
    } catch (final IOException e) {
        log.error("An error occurred while trying to export the list to CSV: ", e);
        return false;
    }

    return true;
}
 
开发者ID:manami-project,项目名称:manami,代码行数:22,代码来源:CsvExporter.java

示例3: writeTermMap

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
private void writeTermMap() throws IOException {
	BufferedWriter w = new BufferedWriter(new FileWriter(outputFile));
	CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
	for (int rfBin = rfSize-1 ; rfBin >= 0 ; rfBin--) {
		List<String> columns = new ArrayList<String>(psSize);
		for (int psBin = 0 ; psBin < psSize ; psBin++) {
			if (termMap[psBin][rfBin] == null) {
				columns.add("");
			} else {
				columns.add(termMap[psBin][rfBin]);
			}
		}
		csvWriter.write(columns);
	}
	csvWriter.close();
}
 
开发者ID:tkuhn,项目名称:memetools,代码行数:17,代码来源:MakeTermMap.java

示例4: run

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
public void run() throws IOException {
	init();
	BufferedReader r = new BufferedReader(new FileReader(inputFile), 64*1024);
	CsvListReader csvReader = new CsvListReader(r, MemeUtils.getCsvPreference());
	BufferedWriter w = new BufferedWriter(new FileWriter(outputFile), 64*1024);
	CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
	List<String> line = csvReader.read();
	int col;
	if (colIndexOrName.matches("[0-9]+")) {
		col = Integer.parseInt(colIndexOrName);
	} else {
		col = line.indexOf(colIndexOrName);
	}
	line.add(newColName);
	csvWriter.write(line);
	while ((line = csvReader.read()) != null) {
		if (line.get(col).matches(regex)) {
			line.add("1");
		} else {
			line.add("0");
		}
		csvWriter.write(line);
	}
	csvReader.close();
	csvWriter.close();
}
 
开发者ID:tkuhn,项目名称:memetools,代码行数:27,代码来源:ApplyRegex.java

示例5: processTerms

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
private void processTerms() throws IOException {
	log("Filtering and writing output...");
	int n = 0;
	Writer w = new BufferedWriter(new FileWriter(outputFile));
	CsvListWriter csvWriter = new CsvListWriter(w, MemeUtils.getCsvPreference());
	csvWriter.write("COUNT", "TERM");
	for (String term : ngrams.keySet()) {
		int c = ngrams.get(term);
		if (c >= t) {
			n++;
			logProgress(n);
			csvWriter.write(c, term);
		}
	}
	csvWriter.close();
	log("Number of n-grams after filtering: " + n);
}
 
开发者ID:tkuhn,项目名称:memetools,代码行数:18,代码来源:CountNgrams.java

示例6: writeCsv

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
public static <V> void writeCsv(final DataFrame<V> df, final OutputStream output)
throws IOException {
    try (CsvListWriter writer = new CsvListWriter(new OutputStreamWriter(output), CsvPreference.STANDARD_PREFERENCE)) {
        final String[] header = new String[df.size()];
        final Iterator<Object> it = df.columns().iterator();
        for (int c = 0; c < df.size(); c++) {
            header[c] = String.valueOf(it.hasNext() ? it.next() : c);
        }
        writer.writeHeader(header);
        final CellProcessor[] procs = new CellProcessor[df.size()];
        final List<Class<?>> types = df.types();
        for (int c = 0; c < df.size(); c++) {
            final Class<?> cls = types.get(c);
            if (Date.class.isAssignableFrom(cls)) {
                procs[c] = new ConvertNullTo("", new FmtDate("yyyy-MM-dd'T'HH:mm:ssXXX"));
            } else {
                procs[c] = new ConvertNullTo("");
            }
        }
        for (final List<V> row : df) {
            writer.write(row, procs);
        }
    }
}
 
开发者ID:cardillo,项目名称:joinery,代码行数:25,代码来源:Serialization.java

示例7: writeCSVFile

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
public static void writeCSVFile(File file, List<List<String>> rows)
		throws IOException {
	StringWriter stringWriter = new StringWriter();
	CsvListWriter csvWriter = new CsvListWriter(stringWriter,
			CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);

	for (List<String> list : rows) {
		csvWriter.write(list);
	}
	csvWriter.close();

	PrintWriter printWriter = new PrintWriter(file);
	printWriter.println(stringWriter.toString());
	stringWriter.close();
	printWriter.close();
}
 
开发者ID:GreenDelta,项目名称:olca-converter,代码行数:17,代码来源:ES2MappingFileUtil.java

示例8: CreateSparseNumericData

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
@Ignore("This is a test only for convenience")
@Test
public void CreateSparseNumericData() throws IOException
{
	FileWriter f = new FileWriter("SparseNumbersOnly.csv"); 
	CsvListWriter ff = new CsvListWriter(f, CsvPreference.STANDARD_PREFERENCE);
	
	final int rowsToProduce = 1000000;
	int j = 33;
	for(int i = 0; i < rowsToProduce; i++)
	{
		if(j == 0) j = 2;
		ff.write(i, i*j, i/(double)j);
		j = i*j % 1843;
	}
	ff.close();
}
 
开发者ID:super-csv,项目名称:super-csv,代码行数:18,代码来源:SparseDataCreator.java

示例9: test

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
@Test
public void test() throws IOException, TransformationException {
	File tempDir = Files.createTempDirectory("CsvDictionaryTest").toFile();
	tempDir.createNewFile();
	File dictFile = new File(tempDir, "dictFile.txt");
	CsvPreference customCsvPref = new CsvPreference.Builder('"', '\t', "\n").build();
	try (CsvListWriter writer = new CsvListWriter(new OutputStreamWriter(new FileOutputStream(dictFile.toString()), "UTF-8"), customCsvPref)) {
		writer.write(new String[] {"a", "b"});
		writer.write(new String[] {"c", "d"});
	}

	CsvDictionary dict = new CsvDictionary();
	dict.setFilePath(dictFile.toString());
	dict.setFileDelimiter("\t");
	dict.afterPropertiesSet();

	DictionaryTransformer transformer = new DictionaryTransformer();
	transformer.setDictionary(dict);

	assertEquals("b", transformer.transform("a"));
	assertEquals("b", transformer.transform("b"));
	assertEquals("d", transformer.transform("c"));
	assertEquals("d", transformer.transform("d"));
	assertEquals("e", transformer.transform("e"));
}
 
开发者ID:RBGKew,项目名称:Reconciliation-and-Matching-Framework,代码行数:26,代码来源:CsvDictionaryTest.java

示例10: flushTriples

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
public static void flushTriples(Iterable<KiWiTriple> tripleBacklog, OutputStream out) throws IOException {
    CsvListWriter writer = new CsvListWriter(new OutputStreamWriter(out), CsvPreference.STANDARD_PREFERENCE);

    // reuse the same array to avoid unnecessary object allocation
    Object[] rowArray = new Object[10];
    List<Object> row = Arrays.asList(rowArray);

    for(KiWiTriple t : tripleBacklog) {
        rowArray[0] = t.getId();
        rowArray[1] = t.getSubject();
        rowArray[2] = t.getPredicate();
        rowArray[3] = t.getObject();
        rowArray[4] = t.getContext();
        rowArray[5] = t.getCreator();
        rowArray[6] = t.isInferred();
        rowArray[7] = t.isDeleted();
        rowArray[8] = t.getCreated();
        rowArray[9] = t.getDeletedAt();

        writer.write(row, tripleProcessors);
    }
    writer.close();
}
 
开发者ID:apache,项目名称:marmotta,代码行数:24,代码来源:PGCopyUtil.java

示例11: getCsv

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected String getCsv(final JFreeContext ctx) {
  return Csv.write(new CsvWriter() {
    @Override
    public void write(CsvListWriter csv) throws IOException {
      final DateFormat yearOnly = new SimpleDateFormat("YYYY");
      csv.write("Year", "Outbreaks");
      final List<TimeSeriesDataItem> items = ((ATSCollection)ctx.dataset()).getSeries(0)
          .getItems();
      for (TimeSeriesDataItem i : items) {
        csv.write(yearOnly.format(i.getPeriod().getStart()), i.getValue()
            .intValue() + "");
      }
    }});
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:17,代码来源:CotsOutbreakBuilder.java

示例12: getCsv

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
@Override
protected String getCsv(final JFreeContext ctx) {
  final CategoryDataset dataset = (CategoryDataset)ctx.dataset();
  return Csv.write(new CsvWriter() {
    @Override
    public void write(CsvListWriter csv) throws IOException {
      @SuppressWarnings("unchecked")
      List<String> columnKeys = dataset.getColumnKeys();
      @SuppressWarnings("unchecked")
      List<String> rowKeys = dataset.getRowKeys();
      final List<String> heading = ImmutableList.<String>builder()
          .add(String.format("%s %s", ctx.region(), ctx.type()))
          .addAll(columnKeys)
          .build();
      csv.write(heading);
      for (String row : rowKeys) {
        List<String> line = newLinkedList();
        line.add(row);
        for (String col : columnKeys) {
          line.add(formatNumber("%.1f", dataset.getValue(row, col)));
        }
        csv.write(line);
      }
    }});
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:26,代码来源:AbstractGroundCoverBuilder.java

示例13: getCsv

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
@Override
protected String getCsv(final JFreeContext ctx) {
  final ADCDataset dataset = (ADCDataset)ctx.dataset();
  return Csv.write(new CsvWriter() {
    @Override
    public void write(CsvListWriter csv) throws IOException {
      @SuppressWarnings("unchecked")
      List<String> columnKeys = dataset.getColumnKeys();
      @SuppressWarnings("unchecked")
      List<String> rowKeys = dataset.getRowKeys();
      final List<String> heading = ImmutableList.<String>builder()
          .add(format("%s %s", ctx.region().getProperName(), ctx.type().getLabel()))
          .addAll(columnKeys)
          .build();
      csv.write(heading);
      for (String row : rowKeys) {
        List<String> line = newLinkedList();
        line.add(row);
        for (String col : columnKeys) {
          final Number n = dataset.getValue(row, col);
          line.add(n == null ? "" : format("%.1f", n.doubleValue()));
        }
        csv.write(line);
      }
    }});
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:27,代码来源:MarineBarChartBuilder.java

示例14: getCsv

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
@Override
protected String getCsv(final JFreeContext ctx) {
  final CategoryDataset dataset = (CategoryDataset)ctx.dataset();
  return Csv.write(new CsvWriter() {
    @Override
    public void write(CsvListWriter csv) throws IOException {
      @SuppressWarnings("unchecked")
      List<String> columnKeys = dataset.getColumnKeys();
      @SuppressWarnings("unchecked")
      List<String> rowKeys = dataset.getRowKeys();
      final List<String> heading = ImmutableList.<String>builder()
          .add(String.format("%s %s", ctx.region().getProperName(), ctx.type().getLabel()))
          .addAll(columnKeys)
          .build();
      csv.write(heading);
      for (String row : rowKeys) {
        List<String> line = Lists.newArrayList();
        line.add(row);
        for (String col : columnKeys) {
          final Number n = dataset.getValue(row, col);
          line.add(n == null ? "" : String.format("%.1f", n.doubleValue()));
        }
        csv.write(line);
      }
    }});
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:27,代码来源:MarineTrendsBuilder.java

示例15: getCsv

import org.supercsv.io.CsvListWriter; //导入依赖的package包/类
@Override
protected String getCsv(final JFreeContext ctx) {
  final CategoryDataset dataset = (CategoryDataset)ctx.dataset();
  return Csv.write(new CsvWriter() {
    @Override
    public void write(CsvListWriter csv) throws IOException {
      csv.writeHeader((ctx.region() == Region.GBR?"Region":"Catchment"),
          (String)dataset.getRowKey(0), (String)dataset.getRowKey(1),
          (String)dataset.getRowKey(2), (String)dataset.getRowKey(3));
      DecimalFormat f = new DecimalFormat(".##");
      for(int cat=0;cat<dataset.getColumnCount();cat++) {
          csv.write(dataset.getColumnKey(cat), f.format(dataset.getValue(0, cat)),
              f.format(dataset.getValue(1, cat)), f.format(dataset.getValue(2, cat)),
              f.format(dataset.getValue(3, cat)));
      }
    }});
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:18,代码来源:WetlandsLossBuilder.java


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