Show Table of Contents
12.22. Implementing a Binary Source Reader
- To implement a binary source reader, observe the following
parsemethod implementation:public static class BinaryFormatXXReader implements SmooksXMLReader, StreamReader { @ConfigParam private String xProtocolVersion; @ConfigParam private int someOtherXProtocolConfig; // etc... public void parse(InputSource inputSource) throws IOException, SAXException { // Use the InputStream (binary) on the InputSource... InputStream binStream = inputSource.getByteStream(); // Create and configure the data decoder... BinaryFormatXDecoder xDecoder = new BinaryFormatXDecoder(); xDecoder.setProtocolVersion(xProtocolVersion); xDecoder.setSomeOtherXProtocolConfig(someOtherXProtocolConfig); xDecoder.setXSource(binStream); // Generate the XML Events on the contentHandler... contentHandler.startDocument(); // Use xDecoder to fire startElement, endElement etc events on the contentHandler (see previous section)... contentHandler.endDocument(); } // etc.... } - Configure the
BinaryFormatXXReaderreader in your Smooks configuration as you would any other reader:<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"> <reader class="com.acme.BinaryFormatXXReader"> <params> <param name="xProtocolVersion">2.5.7</param> <param name="someOtherXProtocolConfig">1</param> ... etc... </params> </reader> ... Other Smooks configurations e.g. <jb:bean> configs for binding the binary data into Java objects... </smooks-resource-list> - Run the Smooks execution code (note the
InputStreamsupplied to theStreamSource). In this case, two results are generated: XML and Java objects.StreamResult xmlResult = new StreamResult(xmlOutWriter); JavaResult javaResult = new JavaResult(); InputStream xBinaryInputStream = getXByteStream(); smooks.filterSource(new StreamSource(xBinaryInputStream), xmlResult, javaResult); // etc... Use the beans in the javaResult...

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.