users@fi.java.net

Re: Parsing Octets

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 16 Nov 2005 10:12:57 +0100

Hi Tony,

You may want to add yourself to this list then you will be able to
receive replies directly.


Tony Seebregts wrote:
> Am new to Fast Infoset and just can't figure out how to retrieve a byte
> array from a fast infoset document. The byte array was encoded using
> StAXDocumentSerializer writeOctets() and I'm trying to read it back
> using a StAXDocumentParser.
>
> Any help would be appreciated.
>

The following code shows you how:

bytes[] b = parser.getTextAlgorithmBytes();
if (b != null) {
     int type = parser.getTextAlgorithmIndex();

     int start = parser.getTextAlgorithmStart();
     int length = parser.getTextAlgorithmLength();

     bytes[] clone = parser.getTextAlgorithmBytesClone();
}

It is all predicated on there being octets to process i.e. if
parser.getTextAlgorithmBytes() returns a non null value. If it is null
then characters are present and the standard StAX methods can be used.

Currently StAXDocumentSerializer writeOctets() only supports the
encoding of octets that would otherwise be base64 encoded to produce
characters.

So when parsing the parser.getTextAlgorithmIndex() will return:

    org.jvnet.fastinfoset.EncodingAlgorithmIndexes.BASE64

Note that it is possible to get other types if say the SAX serializer
was used. The SAX serializer has much more advanced functionality to
encoded different types of binary data, for example arrays of integers.

The standard character based methods of the StAX parser will always
return characters and convert the bytes if necessary.

Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109