サーブレット出力ストリームを介して出力する場合、次のコードで破損した zip ファイルが生成されるのはなぜですか? FileOutputStream を使用してローカルで ZIP をディスクに書き込む場合、出力ストリームが破損しているようには見えません。
// Create zip stream
ZipOutputStream zos = new ZipOutputStream(this.servletOutputStream);
// prepare a new entry
ZipEntry zipEntry = new ZipEntry(forZip.getName());
zipEntry.setSize(forZip.getTotalSpace());
zipEntry.setTime(System.currentTimeMillis());
// write entry
zos.putNextEntry(zipEntry);
// write the file to the entry
FileInputStream toBeZippedInputStream = new FileInputStream(forZip);
IOUtils.copy(toBeZippedInputStream, zos);
zos.flush();
// close entry
zos.closeEntry();
// close the zip
zos.finish();
zos.close();
this.servletOutputStream.flush();
this.servletOutputStream.close();
// close output stream
IOUtils.closeQuietly(toBeZippedInputStream);
これはおそらく、ストリームのフラッシュ/クローズの順序に問題がありますか?