annotate artifacts/src/main/java/org/dive4elements/river/exports/StepCSVWriter.java @ 6611:dfdeed3e997e

Shorten and correct waterlevel not in gauge string
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 18 Jul 2013 17:54:44 +0200
parents af13ceeba52a
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2575
diff changeset
9 package org.dive4elements.river.exports;
2575
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11 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
12
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
13 import java.util.ArrayList;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
14 import java.util.Arrays;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
16 /**
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
17 * 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
18 * 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
19 * 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
20 */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21 public class StepCSVWriter {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
22
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23 /** 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
24 CSVWriter writer = null;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25 /** Buffer of strings (values). */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26 ArrayList<String> buffer;
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
27
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
29 /** Trivial constructor. */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30 public StepCSVWriter() {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
31 buffer = new ArrayList<String>();
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
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35 /** Set writer. */
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36 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
37 this.writer = writer;
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
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
40
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41 /** 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
42 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
43 buffer.add(value);
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
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 /** 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
48 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
49 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
50 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
51
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
52
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
53 /** 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
54 public void flush() {
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
55 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
56 buffer.clear();
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
57 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
58 }
475dd07c2cb1 New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
59 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org