comparison src/main/java/org/dive4elements/artifacts/httpclient/http/response/StringResponseHandler.java @ 71:a857866d162f

Moved directories to org.dive4elements
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 11:14:14 +0200
parents src/main/java/de/intevation/artifacts/httpclient/http/response/StringResponseHandler.java@f314a514de5f
children 133281653904
comparison
equal deleted inserted replaced
70:da691e917f98 71:a857866d162f
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8 package de.intevation.artifacts.httpclient.http.response;
9
10 import java.io.ByteArrayOutputStream;
11 import java.io.InputStream;
12 import java.io.IOException;
13 import java.io.OutputStream;
14
15 import org.restlet.Response;
16
17 /**
18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
19 */
20 public class StringResponseHandler extends StreamResponseHandler {
21
22 public StringResponseHandler() {
23 }
24
25 @Override
26 public Object handle(Response response) throws IOException {
27 InputStream in = (InputStream) super.handle(response);
28 OutputStream out = new ByteArrayOutputStream();
29
30 byte[] b = new byte[4096];
31 int i = -1;
32 while ((i = in.read(b)) > 0) {
33 out.write(b, 0, i);
34 }
35 out.close();
36
37 return out.toString();
38 }
39 }
40 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org