[PATCH 1 of 5] issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc

Wald Commits scm-commit at wald.intevation.org
Wed Sep 25 10:29:54 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1380097812 -7200
# Node ID 8bd13f10d555bb5814e990b70367e2bf3a407032
# Parent  1866aa3a3bfc7be9947172df28efd2ef5cc08bb7
issue1494: Prepare HttpClient to use a specified encoding for collectionOut. Doc.

diff -r 1866aa3a3bfc -r 8bd13f10d555 src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java
--- a/src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java	Mon Sep 16 17:11:21 2013 +0200
+++ b/src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java	Wed Sep 25 10:30:12 2013 +0200
@@ -10,6 +10,10 @@
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+import java.nio.charset.Charset;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -41,6 +45,7 @@
 
 
 /**
+ * Client to artifact-server.
  * @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
  */
 public class HttpClientImpl implements HttpClient {
@@ -76,6 +81,12 @@
 
     private String localeString;
 
+    /**
+     * The Charset used for encoding the collectionOut output.
+     * If not set, the system/java default will be used (UTF-8).
+     */
+    private Charset charset;
+
     private static final ThreadLocal<Client> CLIENT =
         new ThreadLocal<Client>() {
             @Override
@@ -87,6 +98,22 @@
 
     public HttpClientImpl(String serverUrl) {
         this.serverUrl = serverUrl;
+        setEncoding(null);
+    }
+
+
+    /**
+     * Sets the encoding.
+     *
+     * Currently the encoding is only
+     * respected in the collectionOut-method!
+     *
+     * It was implemented to allow csv export to be in another than the
+     * sensible default (UTF-8) and allow easier integration
+     * e.g. in proprietary products.
+     */
+    public void setEncoding(Charset charset) {
+        this.charset = charset;
     }
 
 
@@ -409,9 +436,7 @@
 
 
     /**
-     * This method triggers the out() operation of a Collection. The result of
-     * this operation is written to <i>out</i> directly - there is no return
-     * value.
+     * Write out() operation of a Collection to <i>out</i>.
      *
      * @param doc The request document for the out() operation.
      * @param uuid The identifier of the Collection.


More information about the Dive4elements-commits mailing list