Ouch.. Could I make the READ a blocking one... thus it would wait until the source is really depleted?
** Martin 2009/8/10 Russell Simpkins <[email protected]>: > > Yes. That is exactly the point i was trying to make erik. > >> Date: Mon, 10 Aug 2009 14:30:59 +0200 >> From: [email protected] >> To: [email protected] >> Subject: Re: Output to input stream for streaming? >> >> That won't work. Servlets are synchronous; they don't expect anyone >> writing the output once the servlet finished. >> >> Regards, >> Erik. >> >> >> Russell Simpkins wrote: >> > Its not that anything is missing per se, but if you run your output writer >> > in a separate thread, then the rest of your processing is free to continue >> > and in your case I'm guessing that the processing has finished before your >> > output writing has completed. When your servlet finishes, the last thing >> > that happens is the output stream gets closed. Try doing the write outside >> > of a thread and see if you get the same exception. >> > >> > Russ >> > >> > >> >> Date: Mon, 10 Aug 2009 15:03:13 +0300 >> >> Subject: Re: Output to input stream for streaming? >> >> From: [email protected] >> >> To: [email protected] >> >> >> >> Well well.. I do not understand why it is not possible, in principle. >> >> The input is there. The output is there... what's missing? >> >> >> >> ** >> >> Martin >> >> >> >> 2009/8/10 Russell Simpkins <[email protected]>: >> >> >> >>> 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 >> >>>> >> >>>> >> >>>> >> >> -- >> Erik van Oosten >> http://day-to-day-stuff.blogspot.com/ >> >> >> >> --------------------------------------------------------------------- >> 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 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
