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=66ad3dea875e1f8edcc65c02aca1ba7bcfa71a7d;hp=e7afe952b1fdf27f1b3a04793b35c04701002bff;hpb=e9684d1e123f28be890fd86d8dfe67cf55985b0e;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 e7afe952b..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