We've had similar issues reported in stackoverflow.com and elsewhere. HTTP connections can be shut down if there is no activity for a while. Generating a file with POI can be slow so the connection might be closed while the file is still being generated. I suggest using search tools or GenAI to track down answers on the internet. POI has a DeferredGeneration sample that was submitted to us by a user who said that the approach they championed helped with reducing the delays where no bytes were being exchanged. https://poi.apache.org/components/spreadsheet/examples.html (listed near bottom)
On Wed, 17 Sept 2025 at 16:29, Dominik Stadler <dominik.stad...@gmx.at.invalid> wrote: > > By "I have tried to write the Excel document to a FileOutputStream > instead", do you mean simply writing the workbook to a file also caused the > exception or rather writing to a file and then streaming out the > file-content to the servlet-response did cause the issue? > > Overall it looks a lot like some issue with the Servlet-Response-Stream and > less with Apache POI. Some "divide-and-conquer" could help, e.g. what if > you simply stream out the same number of random bytes without using Apache > POI? > > D. > > > On Wed, Sep 17, 2025 at 4:11 PM Nicholas DiPiazza < > nicholas.dipia...@gmail.com> wrote: > > > I am trying to write an Excel document with Apache POI 5.x. > > > > I have the following write code: > > > > private void writeWorkbookToResponse(XSSFWorkbook outputWorkbook, > > HttpServletResponse response) throws IOException { > > try (OutputStream outputStream = response.getOutputStream(); > > BufferedOutputStream bos = new > > BufferedOutputStream(outputStream)) { > > outputWorkbook.write(bos); > > bos.flush(); > > } > > } > > > > When attempting to save the document, I get the following exception thrown: > > > > java.io.IOException: Broken pipe > > at java.base/sun.nio.ch.FileDispatcherImpl.write0(Native Method) > > at > > java.base/sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:62) > > at > > java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:132) > > at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:76) > > at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:53) > > at > > java.base/sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:532) > > at org.apache.tomcat.util.net > > .NioChannel.write(NioChannel.java:125) > > at > > org.apache.tomcat.util.net > > .NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1411) > > at > > org.apache.tomcat.util.net > > .SocketWrapperBase.doWrite(SocketWrapperBase.java:732) > > at > > org.apache.tomcat.util.net > > .SocketWrapperBase.flushBlocking(SocketWrapperBase.java:698) > > at > > org.apache.tomcat.util.net > > .SocketWrapperBase.flush(SocketWrapperBase.java:683) > > at > > > > org.apache.coyote.http11.Http11OutputBuffer$SocketOutputBuffer.flush(Http11OutputBuffer.java:574) > > at > > > > org.apache.coyote.http11.filters.ChunkedOutputFilter.flush(ChunkedOutputFilter.java:156) > > at > > > > org.apache.coyote.http11.Http11OutputBuffer.flush(Http11OutputBuffer.java:216) > > at > > org.apache.coyote.http11.Http11Processor.flush(Http11Processor.java:1271) > > at > > org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:408) > > at org.apache.coyote.Response.action(Response.java:208) > > at > > org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:300) > > at > > org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:266) > > at > > > > org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:133) > > at > > > > org.springframework.security.web.util.OnCommittedResponseWrapper$SaveContextServletOutputStream.flush(OnCommittedResponseWrapper.java:524) > > at > > java.base/java.io > > .BufferedOutputStream.flush(BufferedOutputStream.java:143) > > at > > > > org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.flush(ZipArchiveOutputStream.java:974) > > at > > java.base/java.io.FilterOutputStream.flush(FilterOutputStream.java:153) > > at > > > > java.xml/com.sun.org.apache.xml.internal.serializer.WriterToUTF8Buffered.flush(WriterToUTF8Buffered.java:472) > > at > > > > java.xml/com.sun.org.apache.xml.internal.serializer.ToStream.flushWriter(ToStream.java:271) > > at > > > > java.xml/com.sun.org.apache.xml.internal.serializer.ToXMLStream.endDocument(ToXMLStream.java:227) > > at > > > > java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:137) > > at > > > > java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:96) > > at > > > > java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:718) > > at > > > > java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:780) > > at > > > > java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:395) > > at > > > > org.apache.poi.openxml4j.opc.StreamHelper.saveXmlInStream(StreamHelper.java:79) > > at > > > > org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller.marshall(ZipPackagePropertiesMarshaller.java:53) > > at > > org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:575) > > at > > org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1487) > > at > > org.apache.poi.ooxml.POIXMLDocument.write(POIXMLDocument.java:227) > > I have tried to write the Excel document to a FileOutputStream instead of > > to the servlet output stream, and it didn't seem to fix anything. > > > > What might cause this behavior? > > > > > > https://stackoverflow.com/questions/79767424/apache-poi-broken-pipe-when-calling-org-apache-poi-ooxml-poixmldocument-write > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org