try
{
HttpResponse response = (HttpResponse)src;
ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
OutputStream outstream = bos;
ResponseWriter writer = new ResponseWriter(outstream, encoding);
writer.println(response.getStatusLine());
Iterator item = response.getHeaderIterator();
while (item.hasNext())
{
Header header = (Header)item.next();
writer.print(header.toExternalForm());
}
writer.println();
writer.flush();
if (response.hasBody())
{
OutputHandler handler = response.getBody();
Header transferenc = response.getFirstHeader(HttpConstants.HEADER_TRANSFER_ENCODING);
if (transferenc != null)
{
response.removeHeaders(HttpConstants.HEADER_CONTENT_LENGTH);
if (transferenc.getValue().indexOf(HttpConstants.TRANSFER_ENCODING_CHUNKED) != -1)
{
outstream = new ChunkedOutputStream(outstream);
}
}
handler.write(RequestContext.getEvent(), outstream);
if (outstream instanceof ChunkedOutputStream)
{
((ChunkedOutputStream)outstream).finish();
}
}
outstream.flush();
bos.flush();
byte[] result = bos.toByteArray();
outstream.close();
writer.close();
bos.close();
String output = null;
try
{