-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: how to get "binary" to output to XML as base64 enc
PostPosted: Wed Aug 03, 2005 3:08 pm 
Newbie

Joined: Wed Aug 03, 2005 2:23 pm
Posts: 4
Hibernate version: 3.0

Some tables in my database contain binary data. So, in my configuration file, you might find something like:

Code:
        <property name="binarydata" column="BinaryData" node="BinaryData" type="binary"  not-null="true" />


In my class, I have a field named "BinaryData", which is a "byte[]" This receives the bytes properly, and everything is fine.

But I also need to turn my class into an XML document. So, I create a session, with the entity-mode set to DOM4J.

Code:
Session session = IPSSessionFactory.currentSession();
Session dom4jSession = session.getSession(EntityMode.DOM4J);

// insert Document creating code, queries, etc.
Element elt = dom4jSession.createQuery("from someTable").uniqueResult();


Then I use the Dom4J stuff to create an XMLWriter, and all of the XML gets output just as I'd expect. Except that the binary field (as byte[]) gets generated as the hex-value of the bytes. What I'd really like to do is have that field export the base64 representation of those bytes, and I'm not sure the best way to do this.

Any help in this would be greatly appreciated.

Thanks,
-Dan.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 3:44 pm 
Newbie

Joined: Tue Jul 26, 2005 1:25 pm
Posts: 14
I've used this for encoding/decoding base64 from byte[] to String and back.

org.apache.xerces.utils.Base64

It's worked well for me -


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 4:15 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
You might have a look at Jakarta Commons Codec.
http://jakarta.apache.org/commons/codec/

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 4:21 pm 
Newbie

Joined: Wed Aug 03, 2005 2:23 pm
Posts: 4
sarahl2 wrote:
I've used this for encoding/decoding base64 from byte[] to String and back.

org.apache.xerces.utils.Base64

It's worked well for me -


Thanks, this will be useful. But this is a collection of static routines. But it's not exactly what I'm trying to do. What I'd like to do is have a class, then reads/writes bytes to the database. But when asked for it's textual representation, (which Dom4j does so it can output it to XML) returns the bytes as Base64 encoded, instead of as a hex-string.

From doing more reading, it looks like I should make a custom type. I guess I could just make a sub-class of "BinaryType" and just override it's "toString" and "fromStringValue" calls? Does that sound like the right way to go?

-Dan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.