gpt4 book ai didi

wicket - Wicket 1.5 中的 WebResponse.getOutputStream()?

转载 作者:行者123 更新时间:2023-12-01 14:36:07 25 4
gpt4 key购买 nike

此代码在 1.4 中对我有用:

WebResponse response = (org.apache.wicket.request.http.WebResponse) getResponse();
response.setAttachmentHeader("List.xls");
response.setContentType("application/ms-excel");
OutputStream out = response.getOutputStream();
WritableWorkbook workbook = Workbook.createWorkbook(out);
.....
.....
workbook.write();
workbook.close();

我在 1.5 中看到没有 WebResponse.getOutputStream() - 但它没有被标记为已弃用?

我查看了 1.5 迁移指南,但看不到任何明显的解决方案。

谁能告诉我在 1.5 中我应该怎么做。

最佳答案

您可以将 Response 包装在 OutputStream 中:

public final class ResponseOutputStream extends OutputStream {
private final Response response;
private final byte[] singleByteBuffer = new byte[1];
public ResponseOutputStream(Response response) {
this.response = response;
}
@Override
public void write(int b) throws IOException {
singleByteBuffer[0] = (byte) b;
write(singleByteBuffer);
}
@Override
public void write(byte[] b) throws IOException {
response.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (off == 0 && len == b.length) {
this.write(b);
} else {
super.write(b, off, len);
}
}
}

关于wicket - Wicket 1.5 中的 WebResponse.getOutputStream()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8163119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com