You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Makundi <ma...@koodaripalvelut.com> on 2009/08/10 13:49:58 UTC

Output to input stream for streaming?

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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Output to input stream for streaming?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> wb.write(baos);
> InputStream is = new ByteArrayInputStream(baos.toByteArray());

Yes, I did that as a workarnound, but I would like to know how to do
it with the piped streams.

**
Martin

>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Output to input stream for streaming?

Posted by Reinhard Nägele <re...@mgm-tp.com>.
How about this:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
wb.write(baos);
InputStream is = new ByteArrayInputStream(baos.toByteArray());


Martin Makundi schrieb:
> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Output to input stream for streaming?

Posted by Erik van Oosten <e....@grons.nl>.
With 'output' I meant the servlet request output. But perhaps I 
misunderstood the question.

I guess the problem is that you close 'inputStream' as soon as the 
request is finished. The thread that tries to write to it is still 
active at that moment.

Regards,
    Erik.


Martin Makundi wrote:
> Maybe the thread is wrongly written, yes but a servlet CAN read a
> FILE. A file is always another PROCESS (which supplies the file
> contents, yes, it's the disk driver etc.). So a similar configuration
> should be possible between a write operation and an input stream.
>
> Anybody have experience with pipedstreams? There is an article about
> it here, but I may have misunderstood the details:
> http://ostermiller.org/convert_java_outputstream_inputstream.html
>
> **
> Martin
>
> 2009/8/10 Erik van Oosten <e....@grons.nl>:
>   
>> That won't work. Servlets are synchronous; they don't expect anyone writing
>> the output once the servlet finished.
>>
>> Regards,
>>   Erik
>>
>>     

-- 
Erik van Oosten
http://day-to-day-stuff.blogspot.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Output to input stream for streaming?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Maybe the thread is wrongly written, yes but a servlet CAN read a
FILE. A file is always another PROCESS (which supplies the file
contents, yes, it's the disk driver etc.). So a similar configuration
should be possible between a write operation and an input stream.

Anybody have experience with pipedstreams? There is an article about
it here, but I may have misunderstood the details:
http://ostermiller.org/convert_java_outputstream_inputstream.html

**
Martin

2009/8/10 Erik van Oosten <e....@grons.nl>:
> That won't work. Servlets are synchronous; they don't expect anyone writing
> the output once the servlet finished.
>
> Regards,
>   Erik.
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Output to input stream for streaming?

Posted by Reinhard Nägele <re...@mgm-tp.com>.
You need to wait until your executor thread has finished. Then it might 
work.

Future<?> f = Executors.newSingleThreadExecutor().submit(new Runnable() {
      @Override
      public void run() {
        try {
          wb.write(out);
        } catch (IOException e) {
          MarkupUtils.handleUnexpectedException(e);
        }
      }
    });
f.get();



Erik van Oosten schrieb:
> 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: martin.makundi@koodaripalvelut.com
>>> To: users@wicket.apache.org
>>>
>>> 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 <ru...@hotmail.com>:
>>>    
>>>> 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: martin.makundi@koodaripalvelut.com
>>>>> To: users@wicket.apache.org
>>>>>
>>>>> 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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Output to input stream for streaming?

Posted by Russell Simpkins <ru...@hotmail.com>.
I'm new to wicket, but if I wanted to send down file data, I would use a servlet, get the output stream and write the data.
a simple example: 
writeData(InputStream in, HttpServletResponse resp) {   out = resp.getOutputStream();   byte[] data = new byte[1024];   int size = 0;   while ( (size=in.read(data,1024))>=0) {      out.write(data,0,size);   }}
If the file is on disk, then there is no need to do this, but if it's in the db you would do something like this. You can't do something like this in JSP, because JSP adds a new line to all responses. You may run into issues of wicket adds anything to the output stream.
russ

> Date: Mon, 10 Aug 2009 18:10:13 +0300
> Subject: Re: Output to input stream for streaming?
> From: martin.makundi@koodaripalvelut.com
> To: users@wicket.apache.org
> 
> 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 <ru...@hotmail.com>:
> >
> > Yes. That is exactly the point i was trying to make erik.
> >
> >> Date: Mon, 10 Aug 2009 14:30:59 +0200
> >> From: e.vanoosten@grons.nl
> >> To: users@wicket.apache.org
> >> 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: martin.makundi@koodaripalvelut.com
> >> >> To: users@wicket.apache.org
> >> >>
> >> >> 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 <ru...@hotmail.com>:
> >> >>
> >> >>> 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: martin.makundi@koodaripalvelut.com
> >> >>>> To: users@wicket.apache.org
> >> >>>>
> >> >>>> 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: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >
> > _________________________________________________________________
> > 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

_________________________________________________________________
Get your vacation photos on your phone!
http://windowsliveformobile.com/en-us/photos/default.aspx?&OCID=0809TL-HM

Re: Output to input stream for streaming?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
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 <ru...@hotmail.com>:
>
> Yes. That is exactly the point i was trying to make erik.
>
>> Date: Mon, 10 Aug 2009 14:30:59 +0200
>> From: e.vanoosten@grons.nl
>> To: users@wicket.apache.org
>> 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: martin.makundi@koodaripalvelut.com
>> >> To: users@wicket.apache.org
>> >>
>> >> 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 <ru...@hotmail.com>:
>> >>
>> >>> 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: martin.makundi@koodaripalvelut.com
>> >>>> To: users@wicket.apache.org
>> >>>>
>> >>>> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
> _________________________________________________________________
> 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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Output to input stream for streaming?

Posted by Russell Simpkins <ru...@hotmail.com>.
Yes. That is exactly the point i was trying to make erik.

> Date: Mon, 10 Aug 2009 14:30:59 +0200
> From: e.vanoosten@grons.nl
> To: users@wicket.apache.org
> 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: martin.makundi@koodaripalvelut.com
> >> To: users@wicket.apache.org
> >>
> >> 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 <ru...@hotmail.com>:
> >>     
> >>> 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: martin.makundi@koodaripalvelut.com
> >>>> To: users@wicket.apache.org
> >>>>
> >>>> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

_________________________________________________________________
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

Re: Output to input stream for streaming?

Posted by Erik van Oosten <e....@grons.nl>.
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: martin.makundi@koodaripalvelut.com
>> To: users@wicket.apache.org
>>
>> 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 <ru...@hotmail.com>:
>>     
>>> 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: martin.makundi@koodaripalvelut.com
>>>> To: users@wicket.apache.org
>>>>
>>>> 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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Output to input stream for streaming?

Posted by Russell Simpkins <ru...@hotmail.com>.
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: martin.makundi@koodaripalvelut.com
> To: users@wicket.apache.org
> 
> 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 <ru...@hotmail.com>:
> >
> > 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: martin.makundi@koodaripalvelut.com
> >> To: users@wicket.apache.org
> >>
> >> 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: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >
> > _________________________________________________________________
> > 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

_________________________________________________________________
Get free photo software from Windows Live
http://www.windowslive.com/online/photos?ocid=PID23393::T:WLMTAGL:ON:WL:en-US:SI_PH_software:082009

Re: Output to input stream for streaming?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
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 <ru...@hotmail.com>:
>
> 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: martin.makundi@koodaripalvelut.com
>> To: users@wicket.apache.org
>>
>> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
> _________________________________________________________________
> 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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Output to input stream for streaming?

Posted by Russell Simpkins <ru...@hotmail.com>.
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: martin.makundi@koodaripalvelut.com
> To: users@wicket.apache.org
> 
> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

_________________________________________________________________
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