annotate flys-artifacts/src/main/java/de/intevation/flys/exports/StepCSVWriter.java @ 3203:1b9f791937c3

Moved FixationArtifactAccess to new access package. flys-artifacts/trunk@4820 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 28 Jun 2012 08:16:20 +0000
parents 475dd07c2cb1
children
rev   line source
2575
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.exports;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
2
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
3 import au.com.bytecode.opencsv.CSVWriter;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
4
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
5 import java.util.ArrayList;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
6 import java.util.Arrays;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
7
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
8 /**
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
9 * Class to overcome shortcoming of CSVWriter to accept String-Arrays only.
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10 * The StepCSVWriter buffers incoming values, such that rows in a csv can be
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11 * created more dynamically. Do not forget to call flush().
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
12 */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
13 public class StepCSVWriter {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
14
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15 /** Writer to use when calling flush. */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
16 CSVWriter writer = null;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
17 /** Buffer of strings (values). */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
18 ArrayList<String> buffer;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
20
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21 /** Trivial constructor. */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
22 public StepCSVWriter() {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23 buffer = new ArrayList<String>();
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
27 /** Set writer. */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28 public void setCSVWriter(CSVWriter writer) {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29 this.writer = writer;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
31
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33 /** Add a value to next flush. */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34 public void addNext(String value) {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35 buffer.add(value);
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
37
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
38
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
39 /** Add many values to next flush. */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
40 public void addNexts(String ... values) {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41 buffer.addAll(Arrays.asList(values));
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
42 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
45 /** Write the row with csvwriter. */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46 public void flush() {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 writer.writeNext(buffer.toArray(new String[buffer.size()]));
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48 buffer.clear();
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
50 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
51 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org