【发布时间】:2014-03-12 16:08:47
【问题描述】:
我有自己的课程扩展 org.apache.cocoon.serialization.AbstractSerializer
(很基础)
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();
}
}
第一次尝试一切正常,我得到了预期的输出。从第二个开始,我从 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>
【问题讨论】:
标签: java xmlserializer outputstream