Project

Profile

Help

saxon:octets-to-base64Binary(byte[])?

Added by Anonymous over 16 years ago

Legacy ID: #4771607 Legacy Poster: Chapman Flack (jcflack)

Hi, Given a Java function byte[] loadImage() that returns a roughly 4 kB object, saxon:octets-to-base64Binary(foo:loadImage()) works and does what I want done. But I wonder whether I should be concerned about efficiency. As I understand it, the 4 kB byte[] returned by loadImage() is converted, at least in concept, to some representation of a 4k-element xs:integer* before saxon:octets-to-base64Binary() can operate on it. This worries me about both time and space if there are a lot of images involved. I suppose I could have loadImage return a Blob class that simply wraps a byte[] so it would stay a wrapped Java object and escape automatic conversion to a sequence, and then provide a blob-to-base64Binary function. But I guess it's also possible that saxon already optimizes that conversion out in some clever way so that my concern is needless. What's the scoop? Thanks, Chapman Flack


Replies (2)

RE: saxon:octets-to-base64Binary(byte[])? - Added by Anonymous over 16 years ago

Legacy ID: #4771753 Legacy Poster: Michael Kay (mhkay)

Yes: if loadImage() returns a byte[] array, the bytes will be wrapped as Saxon Int64Value objects on return from the function, and then converted back to byte[] when calling octets-to-base64Binary. Your best bet would be to write a Java function loadImageAsBase64 which returns a Base64Binary object by passing the byte[] array directly to the constructor of net.sf.saxon.value.Base64BinaryValue. Michael Kay

RE: saxon:octets-to-base64Binary(byte[])? - Added by Anonymous over 16 years ago

Legacy ID: #4771982 Legacy Poster: Chapman Flack (jcflack)

Thanks! I think what I'll do is abstract that solution out into a Blob class that has constructors from base64Binary and InputStream, and accessors asBase64Binary and toOutputStream. Then I don't need any special function for loadImage, as blob:new(url:open-stream(url:new($img))) would do the trick--and I'm sure this is not the last time such a blob class will be useful. -Chap

    (1-2/2)

    Please register to reply