ingo@0: /* ingo@0: * Copyright (c) 2010 by Intevation GmbH ingo@0: * ingo@0: * This program is free software under the LGPL (>=v2.1) ingo@0: * Read the file LGPL.txt coming with the software for details ingo@0: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@0: */ ingo@0: package de.intevation.artifacts.httpclient.http.response; ingo@0: ingo@0: import java.io.ByteArrayOutputStream; ingo@0: import java.io.InputStream; ingo@0: import java.io.IOException; ingo@0: import java.io.OutputStream; ingo@0: ingo@0: import org.restlet.Response; ingo@0: ingo@0: /** ingo@0: * @author Ingo Weinzierl ingo@0: */ ingo@0: public class StringResponseHandler extends StreamResponseHandler { ingo@0: ingo@0: public StringResponseHandler() { ingo@0: } ingo@0: sascha@32: @Override ingo@0: public Object handle(Response response) throws IOException { ingo@0: InputStream in = (InputStream) super.handle(response); ingo@0: OutputStream out = new ByteArrayOutputStream(); ingo@0: ingo@0: byte[] b = new byte[4096]; ingo@0: int i = -1; ingo@0: while ((i = in.read(b)) > 0) { ingo@0: out.write(b, 0, i); ingo@0: } ingo@0: out.close(); ingo@0: ingo@0: return out.toString(); ingo@0: } ingo@0: } ingo@0: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: