Mercurial > dive4elements > http-client
changeset 93:30b7ca3951c7
issue1494: Add collectionOutEnc(inStream,outStream) function to
handle encoding for output-stream of collectionOut action.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 25 Sep 2013 10:39:59 +0200 |
parents | fcbfc6c597b1 |
children | 31dc80c48936 |
files | src/main/java/org/dive4elements/artifacts/httpclient/http/HttpClientImpl.java |
diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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.