Move various CMS extensions to Argeo SLC.
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / CsvWriter.java
index 4b9fea3faa093ca99e4e47d42c7c3715c359afaa..41ea65dd4903a88af162c640475160929d2c5210 100644 (file)
@@ -1,18 +1,3 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package org.argeo.util;
 
 import java.io.IOException;
@@ -20,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;
 
@@ -33,9 +19,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.
+        * 
+        * @deprecated Use {@link #CsvWriter(OutputStream, Charset)} instead.
+        * 
         */
+       @Deprecated
        public CsvWriter(OutputStream out) {
                this.out = new OutputStreamWriter(out);
        }
@@ -43,21 +32,33 @@ 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);
                } catch (UnsupportedEncodingException e) {
-                       throw new UtilsException("Cannot initialize CSV writer", e);
+                       throw new IllegalArgumentException(e);
                }
        }
 
        /**
-        * 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.
+        * 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.
         */
        public void writeLine(List<?> tokens) {
                try {
@@ -70,14 +71,13 @@ public class CsvWriter {
                        out.write('\n');
                        out.flush();
                } catch (IOException e) {
-                       throw new UtilsException("Could not write " + tokens, e);
+                       throw new RuntimeException("Could not write " + tokens, e);
                }
        }
 
        /**
-        * 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.
+        * 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 {
@@ -94,7 +94,7 @@ public class CsvWriter {
                        out.write('\n');
                        out.flush();
                } catch (IOException e) {
-                       throw new UtilsException("Could not write " + tokens, e);
+                       throw new RuntimeException("Could not write " + tokens, e);
                }
        }