Streaming (large) data

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Streaming (large) data

Martin Renner
Hi,

I have to export a database into a XML file. As the objects contain BLOBs, I implemented a Converter
for BLOBs:

  public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
      Blob blob = (Blob) source;
      context.convertAnother(blob.getBytes(1, (int) blob.length()));

This will read the whole BLOB into a byte array and delegate to EncodedByteArrayConverter. But the
BLOBs are much too large to fit into the heap. So I have to find a way to stream this data (base64
encoded) into the output file.

However, I can not find any method in HierarchicalStreamWriter which would allow to stream character
data.

As I already posted this question on the wrong list (dev instead of user, sorry), I got the hint to
use Woodstox and its interface XMLStreamWriter2, which apparently would allow to stream data. But I
have no idea, how I can get access to the underlying Woodstox writer inside of a Converter.

In the above method, I can call "writer.underlyingWriter()", which returns an instance of
StaxWriter. But this StaxWriter does not give access to its XMLStreamWriter.

How is it possible to stream data from a Converter into the output?

Regards,
Martin

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Streaming (large) data

Jörg Schaible-2
Hi Martin,

Martin Renner wrote:

> Hi,
>
> I have to export a database into a XML file. As the objects contain BLOBs,
> I implemented a Converter for BLOBs:
>
>   public void marshal(Object source, HierarchicalStreamWriter writer,
>   MarshallingContext context) {
>       Blob blob = (Blob) source;
>       context.convertAnother(blob.getBytes(1, (int) blob.length()));
>
> This will read the whole BLOB into a byte array and delegate to
> EncodedByteArrayConverter. But the BLOBs are much too large to fit into
> the heap. So I have to find a way to stream this data (base64 encoded)
> into the output file.
>
> However, I can not find any method in HierarchicalStreamWriter which would
> allow to stream character data.
>
> As I already posted this question on the wrong list (dev instead of user,
> sorry),

Did you only read the top of my answer or also the the bottom with my hints
regarding setText() ... ;-) ?

> I got the hint to use Woodstox and its interface XMLStreamWriter2,
> which apparently would allow to stream data. But I have no idea, how I can
> get access to the underlying Woodstox writer inside of a Converter.
>
> In the above method, I can call "writer.underlyingWriter()", which returns
> an instance of StaxWriter. But this StaxWriter does not give access to its
> XMLStreamWriter.
>
> How is it possible to stream data from a Converter into the output?

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email