我想实现 this page 的例子.
我卡在 getResourceStream()
方法上了。我的应用程序有一个 byte[]
(生成的 XML 文件),用户应该可以下载。问题是我不知道如何将 byte[]
转换为 IResourceStream
。
这是我的:
final AJAXDownload download = new AJAXDownload()
{
private static final long serialVersionUID = 1L;
@Override
protected IResourceStream getResourceStream()
{
ByteArrayResource bar = new ByteArrayResource("TEXT??", xmlFileInBytes);
return (IResourceStream) bar;
}
};
上面的代码给出了一个ClassCastException
。谁能解释一下我该如何解决这个问题?
最佳答案
您可以使用 IResourceStream 的子类 StringResourceStream 并使用字节数组:
你可以这样做:
byte byteArray[] = new byte[1024] //this is the byte array containing the xml which you want to use.
StringResourceStream srs = new StringResourceStream(new String(byteArray));
因此在您的情况下,该方法将如下所示:
final AJAXDownload download = new AJAXDownload()
{
private static final long serialVersionUID = 1L;
@Override
protected IResourceStream getResourceStream()
{
StringResourceStream bar = new StringResourceStream (new String(xmlFileInBytes) );
return (IResourceStream) bar;
}
};
关于java - byte[] 到 Wicket 中的 iresourcestream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16011213/