Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/exports/StepCSVWriter.java @ 5622:b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Data properties are identified by starting with mapfish-data
and they are then split in info value pairs where info
can be the description of the information and value the value
of the information to be transported in the data map.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 09 Apr 2013 19:04:32 +0200 |
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 : |