[PATCH 4 of 5] issue1494: Add collectionOutEnc(inStream, outStream) function to

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


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1380098399 -7200
# Node ID 30b7ca3951c7a52cd632bdc85e74915d85c89cd6
# Parent  fcbfc6c597b1e4641e67c5bd1a479655553b7e3c
issue1494: Add collectionOutEnc(inStream,outStream) function to
handle encoding for output-stream of collectionOut action.

diff -r fcbfc6c597b1 -r 30b7ca3951c7 src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java
--- a/src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java	Wed Sep 25 10:38:54 2013 +0200
+++ b/src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java	Wed Sep 25 10:39:59 2013 +0200
@@ -7,7 +7,10 @@
  */
 package org.dive4elements.artifacts.httpclient.http;
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
@@ -436,6 +439,43 @@
 
 
     /**
+     * Write out() operation of a Collection to <i>out</i>, using buffered
+     * reading and writing and a charset.
+     *
+     * @param in collection out to read from.
+     * @param out The OutputStream to write transcoded answer to.
+     */
+    private void collectionOutEnc(
+        InputStream in,
+        OutputStream out)
+    throws ConnectionException
+    {
+        try {
+            BufferedReader reader =
+                new BufferedReader(new InputStreamReader(in));
+
+            BufferedWriter writer =
+                new BufferedWriter(new OutputStreamWriter(out, this.charset));
+
+            try {
+                    char[] c = new char[4096];
+                    int i;
+                    while ((i = reader.read(c)) >= 0) {
+                        writer.write(c, 0, i);
+                    }
+            }
+            finally {
+                writer.flush();
+                in.close();
+            }
+        }
+        catch (IOException ioe) {
+            throw new ConnectionException(ioe.getMessage(), ioe);
+        }
+    }
+
+
+    /**
      * Write out() operation of a Collection to <i>out</i>.
      *
      * @param doc The request document for the out() operation.


More information about the Dive4elements-commits mailing list