int length = urlConnection.getContentLength();
// if length is not known, use a default value
length = (length > 0 ? length : Tools.DEFAULT_BUFFER_SIZE * 8);
byte[] bytes = IOTools.getBytes(urlConnection.getInputStream(), length);
ResourceContext resourceContext;
// GTNCOMMON-14
if (MIMEUtils.isInterpretableAsText(contentType))
{
// determine the charset of the content, defaulting to UTF-8 if there isn't one
String charset = MIMEUtils.getCharsetFrom(contentType);
String markup = new String(bytes, charset);
resourceContext = WSRPTypeFactory.createResourceContext(contentType, markup, null);
// process markup if needed
if (MIMEUtils.needsRewriting(contentType))
{
resourceContext.setRequiresRewriting(true);
}
}
else
{
resourceContext = WSRPTypeFactory.createResourceContext(contentType, null, bytes);
resourceContext.setRequiresRewriting(false);
}
return WSRPTypeFactory.createResourceResponse(resourceContext);
}