0
我有我自己的類擴展org.apache.cocoon.serialization.AbstractSerializer
(基本相當)什麼關閉AbstractSerializer中的OutputStream?
public class ExcelSerializer extends AbstractSerializer {
private static final XLogger LOG = XLoggerFactory.getXLogger(ExcelSerializer.class);
private ExcelSheetCreator excelSheetCreator;
public ExcelSerializer() {
try {
excelSheetCreator = new ExcelSheetCreator();
} catch (IOException e) {
LOG.error("ERROR", e.getMessage());
}
}
@Override
public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException {
excelSheetCreator.startElement(uri, loc, raw, a);
}
@Override
public void characters(char[] c, int start, int len) throws SAXException {
excelSheetCreator.characters(c, start, len);
}
@Override
public void endElement(String uri, String loc, String raw) throws SAXException {
excelSheetCreator.endElement(uri, loc, raw);
}
@Override
public void endDocument() throws SAXException {
excelSheetCreator.setOutputStream(this.output);
excelSheetCreator.endDocument();
}
}
對於第一次嘗試一切都OK了,我得到了預期的輸出。從第二個開始,我從ExcelSerializer調用的類拋出IOException,因爲流已經關閉。
@Override
public void endDocument() throws SAXException {
try {
workbook.write(outputStream);
} catch (IOException e) {
System.out.println("workbook");
System.out.println("" + e.getMessage());
}
workbook.dispose();
}
我當然沒有關閉輸出流或至少不知道。 我能做些什麼來保持它的開放?
這裏是我的網站地圖:
<map:serializer name="excelSerializer" logger="sitemap.serializer.excelSerializer" src="com.acrys.excel.ExcelSerializer"
mime-type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
</map:serializer>