comparison artifacts/src/main/java/org/dive4elements/river/exports/StepCSVWriter.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/exports/StepCSVWriter.java@bd047b71ab37
children 4897a58c8746
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.exports;
2
3 import au.com.bytecode.opencsv.CSVWriter;
4
5 import java.util.ArrayList;
6 import java.util.Arrays;
7
8 /**
9 * Class to overcome shortcoming of CSVWriter to accept String-Arrays only.
10 * The StepCSVWriter buffers incoming values, such that rows in a csv can be
11 * created more dynamically. Do not forget to call flush().
12 */
13 public class StepCSVWriter {
14
15 /** Writer to use when calling flush. */
16 CSVWriter writer = null;
17 /** Buffer of strings (values). */
18 ArrayList<String> buffer;
19
20
21 /** Trivial constructor. */
22 public StepCSVWriter() {
23 buffer = new ArrayList<String>();
24 }
25
26
27 /** Set writer. */
28 public void setCSVWriter(CSVWriter writer) {
29 this.writer = writer;
30 }
31
32
33 /** Add a value to next flush. */
34 public void addNext(String value) {
35 buffer.add(value);
36 }
37
38
39 /** Add many values to next flush. */
40 public void addNexts(String ... values) {
41 buffer.addAll(Arrays.asList(values));
42 }
43
44
45 /** Write the row with csvwriter. */
46 public void flush() {
47 writer.writeNext(buffer.toArray(new String[buffer.size()]));
48 buffer.clear();
49 }
50 }
51 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org