Martin, I don't think you can do this in a thread because that lets the HttpServletResponse end and close your ServletOutputStream.
Russ > Date: Mon, 10 Aug 2009 14:49:58 +0300 > Subject: Output to input stream for streaming? > From: [email protected] > To: [email protected] > > Hi! > > I have a HSSF document which can be written to an output stream. > However, I want to stream it to the website visitor, which requires an > inputstream... I have tried the following, but it somehow doesn't seem > to work. > > Anybody know what can be done to fix it? > > final PipedInputStream inputStream = new PipedInputStream(); > final PipedOutputStream out; > try { > out = new PipedOutputStream(inputStream); > } catch (IOException e) { > throw new RuntimeException(e); > } > Executors.newSingleThreadExecutor().execute(new Runnable() { > @Override > public void run() { > try { > wb.write(out); > } catch (IOException e) { > MarkupUtils.handleUnexpectedException(e); > } > } > }); > > IResourceStream resourceStream = new IResourceStream() { > /** > * @see org.apache.wicket.util.resource.IResourceStream#close() > */ > public void close() throws IOException { > inputStream.close(); > } > > /** > * @see org.apache.wicket.util.resource.IResourceStream#getContentType() > */ > public String getContentType() { > return getAlternateContentType(); > } > > /** > * @see org.apache.wicket.util.resource.IResourceStream#getInputStream() > */ > public InputStream getInputStream() > throws ResourceStreamNotFoundException { > return inputStream; > } > > /** > * @see org.apache.wicket.util.resource.IResourceStream#getLocale() > */ > public Locale getLocale() { > throw new IllegalAccessError("Method not implemented."); > } > > /** > * @see org.apache.wicket.util.resource.IResourceStream#length() > */ > public long length() { > try { > return inputStream.available(); > } catch (IOException e) { > MarkupUtils.handleUnexpectedException(e); > } > return 0; > } > > /** > * @see > org.apache.wicket.util.resource.IResourceStream#setLocale(java.util.Locale) > */ > public void setLocale(Locale locale) { > throw new IllegalAccessError("Method not implemented."); > } > > /** > * @see org.apache.wicket.util.watch.IModifiable#lastModifiedTime() > */ > public Time lastModifiedTime() { > return > Time.milliseconds(DatabaseServices.getCurrentTimestamp().getTime()); > } > > }; > > java.io.IOException: Pipe closed > at java.io.PipedInputStream.checkStateForReceive(Unknown Source) > at java.io.PipedInputStream.receive(Unknown Source) > at java.io.PipedOutputStream.write(Unknown Source) > at java.io.OutputStream.write(Unknown Source) > at org.apache.poi.poifs.storage.BigBlock.doWriteData(BigBlock.java:55) > at > org.apache.poi.poifs.storage.DocumentBlock.writeData(DocumentBlock.java:220) > at org.apache.poi.poifs.storage.BigBlock.writeBlocks(BigBlock.java:86) > at > org.apache.poi.poifs.filesystem.POIFSDocument$BigBlockStore.writeBlocks(POIFSDocument.java:603) > at > org.apache.poi.poifs.filesystem.POIFSDocument.writeBlocks(POIFSDocument.java:275) > at > org.apache.poi.poifs.filesystem.POIFSFileSystem.writeFilesystem(POIFSFileSystem.java:390) > at > org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1168) > > > > ** > Martin > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > _________________________________________________________________ Get back to school stuff for them and cashback for you. http://www.bing.com/cashback?form=MSHYCB&publ=WLHMTAG&crea=TEXT_MSHYCB_BackToSchool_Cashback_BTSCashback_1x1
