Wicket 导叶响应在末端被修剪

Wicket 导叶响应在末端被修剪,wicket,response,Wicket,Response,我在响应输出数据时遇到问题 @Override protected ResourceResponse newResourceResponse(Attributes attributes) { ResourceResponse response = new ResourceResponse(); response.setContentDisposition(ContentDisposition.INLINE); response.disableCaching();

我在响应输出数据时遇到问题

@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
    ResourceResponse response = new ResourceResponse();
    response.setContentDisposition(ContentDisposition.INLINE);
    response.disableCaching();

    StringBuilder stringBuilder = new StringBuilder(DEFAULT_CONTENT_TYPE);
    stringBuilder.append(";").append(charset == null ? DEFAULT_CHARSET : charset);
    response.setContentType(stringBuilder.toString());
    response.setLastModified(Time.now());

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        fillOutputStream(outputStream);
    } catch (IOException e) {
        logger.error("Error when try to fill data for html report", e);
    }
    String message = null;
    try {
        message = outputStream.toString("UTF-8");
    } catch (UnsupportedEncodingException e) {
        logger.warn("Unknown encoding");
        message = outputStream.toString();
    }
    final CharSequence data = message;

    response.setContentLength(data.length());
    response.setWriteCallback(new WriteCallback() {
        @Override
        public void writeData(Attributes attributes) {
            attributes.getResponse().write(data);
        }
    });

    configureResponse(response, attributes);
    return response;
}
这里的数据是在fillOutputStream()方法中生成并转换为CharSequence的html页面


我已经记录了数据,它的内容是正确的,这是我所期望的,但在结果中,我在最后一页进行了修剪。

字符串的长度不一定等于它的字节计数

改为使用CountingOutputStream(例如来自番石榴)