You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by German Morales <ge...@delta-sys.com> on 2007/08/02 23:07:23 UTC

Re: ResourceLink - call back?

Thanks for the hint.

I use now WebResource, but i couldn't find a class implementing
IResourceStream (which you need to use WebResource) that could get my
byte[] and use it directly.

There is a StringResourceStream, but then i ended up creating a String and
then the class internally asks for its byte[]. I'm not sure if this can
cause memory consumption. Normally i wouldn't care too much, but being
full PDFs involved, it could be an issue.

I ended up creating a ByteArrayResourceStream that takes my byte[] and
uses it directly when needed.

Bye,

German

It seems that Eelco Hillenius wrote:
>> To cut the problem from the source... Do you need to have a file in the
>> file system?
>>
>> We are using a DynamicWebResource that answers a PDF directly from
>> memory.
>> Here some code:
>>
>>    // we have a method that generates the PDF as a byte[]
>>    final byte[] thePDFInBytes = generatePDF();
>>
>>    Resource cResource = new DynamicWebResource() {
>>       protected ResourceState getResourceState() {
>>          return new ResourceState() {
>>                public String getContentType() {
>>                   return "application/pdf";
>>                }
>>                public byte[] getData() {
>>                   return thePDFInBytes;
>>                }
>>             };
>>       }
>>    };
>>
>
> Looks like a fine approach to me. Though it would probably even be
> better if you could just stream it (use WebResource directly).
> ResourceState is a construct that allows for caching, but you probably
> don't need that in this case.
>
> Eelco
>
> ---------------------------------------------------------------------
> 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: ResourceLink - call back?

Posted by Eelco Hillenius <ee...@gmail.com>.
On 8/2/07, German Morales <ge...@delta-sys.com> wrote:
> Thanks for the hint.
>
> I use now WebResource, but i couldn't find a class implementing
> IResourceStream (which you need to use WebResource) that could get my
> byte[] and use it directly.
>
> There is a StringResourceStream, but then i ended up creating a String and
> then the class internally asks for its byte[]. I'm not sure if this can
> cause memory consumption. Normally i wouldn't care too much, but being
> full PDFs involved, it could be an issue.
>
> I ended up creating a ByteArrayResourceStream that takes my byte[] and
> uses it directly when needed.

Actually, *if* you already use byte[] somewhere, you can use
DynamicWebResource just fine. When the resource is serviced, it the
resource state object will be closed/ nulled. My remark about
streaming is when you create the PDF in a streaming fashion, so that
you won't have the whole contents of the PDF in memory (the byte[])
during a request. Is onlly a real issue with large PDFs/ many
requests, so holding it in memory for the duration of a request might
be fine for your case.

Eelco

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


Re: ResourceLink - call back?

Posted by Eelco Hillenius <ee...@gmail.com>.
> There is a StringResourceStream, but then i ended up creating a String and
> then the class internally asks for its byte[]. I'm not sure if this can
> cause memory consumption. Normally i wouldn't care too much, but being
> full PDFs involved, it could be an issue.

You can just directly implement IResourceStream and expose your input
stream via that.

Eelco

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