'Stream closed' exception occurs

这一生的挚爱 提交于 2019-12-11 15:48:42

问题


Recently i am developing a code to export data to excel. I used apache POI for developing this functionality.

Please consider the below code.

public static void prepareDateForCSVGeneration(List<DataList> dataList,HttpServletResponse response)
            throws CashBookingInquiryServiceApplicationException {

         try (ServletOutputStream out = response.getOutputStream()) {
              XSSFWorkbook workbook = new XSSFWorkbook();
              //below method creates headers and rows
              convertToExcel(workbook, dataList);
              response.setContentType("text/vnd.ms-excel");
                response.setHeader("Content-Disposition", "attachment;filename=test.xlsx");
                workbook.write(out);
                out.flush();
            } catch (IOException exception) {
                System.out.println("Exceptin in excel "+exception.getMessage());
                exception.printStackTrace() ;
            }
    }

everything works fine, means excel file downloads successfully but after that in console it throws exception :

Exceptin in excel Stream is closed
[err] java.io.IOException: Stream is closed
[err]     at com.ibm.ws.http.channel.internal.outbound.HttpOutputStreamImpl.validate(HttpOutputStreamImpl.java:213)
[err]     at [internal classes]

Not sure why this is happening.

i referred [java IO Exception: Stream Closed

but i did not find any concrete solution. Can you please suggest what to do? Thanks in advance.

来源:https://stackoverflow.com/questions/50646538/stream-closed-exception-occurs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!