Improve CSV parser and writer.
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / CsvWriter.java
index 97b5191035d83e41d1402b0eff0ff0595b74f03c..41ea65dd4903a88af162c640475160929d2c5210 100644 (file)
@@ -5,6 +5,7 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.nio.charset.Charset;
 import java.util.Iterator;
 import java.util.List;
 
@@ -19,7 +20,11 @@ public class CsvWriter {
         * Creates a CSV writer.
         * 
         * @param out the stream to write to. Caller is responsible for closing it.
+        * 
+        * @deprecated Use {@link #CsvWriter(OutputStream, Charset)} instead.
+        * 
         */
+       @Deprecated
        public CsvWriter(OutputStream out) {
                this.out = new OutputStreamWriter(out);
        }
@@ -27,8 +32,12 @@ public class CsvWriter {
        /**
         * Creates a CSV writer.
         * 
-        * @param out the stream to write to. Caller is responsible for closing it.
+        * @param out      the stream to write to. Caller is responsible for closing it.
+        * @param encoding the encoding to use.
+        * 
+        * @deprecated Use {@link #CsvWriter(OutputStream, Charset)} instead.
         */
+       @Deprecated
        public CsvWriter(OutputStream out, String encoding) {
                try {
                        this.out = new OutputStreamWriter(out, encoding);
@@ -37,6 +46,16 @@ public class CsvWriter {
                }
        }
 
+       /**
+        * Creates a CSV writer.
+        * 
+        * @param out     the stream to write to. Caller is responsible for closing it.
+        * @param charset the charset to use
+        */
+       public CsvWriter(OutputStream out, Charset charset) {
+               this.out = new OutputStreamWriter(out, charset);
+       }
+
        /**
         * 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.