org.apache.wicket.util.resource.IResourceStream を使用して、サーバーで zip ファイルを作成し、出力ストリームで同じ zip ファイルを作成しました。しかし、それは私が頭を壊している次のエラーをスローします。なにか提案を?
Timestamp: 7/25/2012 3:13:28 PM
Error: not well-formed
Source File: XXX
Line: 1, Column: 3
Source Code:
PK
Java コード
AjaxButton one = new AjaxButton("one"){
@Override
public void onSubmit(AjaxRequestTarget target,Form form) {
// TODO Auto-generated method stub
try {
{
IResourceStream iResourceStream = null;
iResourceStream = new AbstractResourceStreamWriter(){
@Override
public String getContentType() {
// TODO Auto-generated method stub
return "application/zip";
}
@Override
public void write(OutputStream output) {
// TODO Auto-generated method stub
File tmpFile = null;
String batchFileName = "batch_"+dateFormat.format(new Date())".zip";
File zipFile = new File(batchFileName);
FileOutputStream zipFileOutputStream = null;
ZipOutputStream zipOutputStream = null;
try
{
zipFileOutputStream = new FileOutputStream(zipFile);
zipOutputStream =
new ZipOutputStream(zipFileOutputStream);
zipOutputStream.setLevel(Deflater.DEFAULT_COMPRESSION);
for(XXX)
{
// create tmpFile zip file here
ZipEntry zipAdd = new ZipEntry(tmpFile.getName());
System.out
.println(tmpFile.getName());
zipOutputStream.putNextEntry(zipAdd);
zipOutputStream.write(IOUtils.toByteArray(new FileInputStream(tmpFile)));
zipOutputStream.closeEntry();
}
}
}
}
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
finally
{
if(zipOutputStream != null){
try {
zipOutputStream.flush();
zipOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(zipFileOutputStream != null){
try {
zipFileOutputStream.flush();
zipFileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try
{
{
InputStream in = new FileInputStream(zipFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
output.write(buf, 0, len);
}
in.close();
output.close();
}
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
};
getRequestCycle()
.setRequestTarget(new ResourceStreamRequestTarget(iResourceStream)
.setFileName("batch.zip"));
} else {
}
} catch (Exception e)
{
}
}