X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=basic%2Fruntime%2Forg.argeo.basic.nodeps%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Futil%2FCsvWriter.java;h=85356e4fed07c4f24e9f980698a983c85d1a17d9;hb=366325583b0b101f3e78fcfda65d3f856cef8617;hp=19086d613a8dafca5e6509bd1b27cc9486cb1572;hpb=7215a19b3ee12587e9d8298c9afd576bf087b017;p=lgpl%2Fargeo-commons.git diff --git a/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/CsvWriter.java b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/CsvWriter.java index 19086d613..85356e4fe 100644 --- a/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/CsvWriter.java +++ b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/util/CsvWriter.java @@ -47,6 +47,25 @@ public class CsvWriter { } } + /** + * Write a CSV line. Also used to write a header if needed (this is + * transparent for the CSV writer): simply call it first, before writing the + * lines. + */ + public void writeLine(Object[] tokens) { + try { + for (int i = 0; i < tokens.length; i++) { + writeToken(tokens[i].toString()); + if (i != (tokens.length - 1)) + out.print(separator); + } + out.print('\n'); + out.flush(); + } catch (IOException e) { + throw new ArgeoException("Could not write " + tokens, e); + } + } + protected void writeToken(String token) throws IOException { // +2 for possible quotes, another +2 assuming there would be an already // quoted string where quotes needs to be duplicated @@ -78,4 +97,13 @@ public class CsvWriter { if (shouldQuote == true) out.print(quote); } + + public void setSeparator(char separator) { + this.separator = separator; + } + + public void setQuote(char quote) { + this.quote = quote; + } + }