Basic Parser
Basic parsers use wide interface XBListener for level 0 which provides single method for each token type.
public void begin(XBBlockTerminationMode terminationMode)
public void attrib(UBNatural attribute)
public void data(InputStream data)
public void end()
For level 1, there is similar interface XBTListener, which also includes additional method for type:
public void typeXBT(XBBlockType blockType)
Usage Examples
try (XBListenerWriter writer = new XBListenerWriter()) {
writer.open(new FileOutputStream("test.xb"));
writer.beginXB(XBBlockTerminationMode.SIZE_SPECIFIED);
writer.attribXB(new UBNat32(1));
writer.attribXB(new UBNat32(2));
writer.endXB();
writer.closeXB();
} catch (IOException | XBProcessingException ex) {
// Process exception
}
try {
XBProducerReader reader = new XBProducerReader();
reader.open(new FileInputStream("test.xb"));
reader.attachXBListener(new XBListener() {
@Override
public void beginXB(XBBlockTerminationMode terminationMode) throws XBProcessingException, IOException {
// Process your data
}
@Override
public void attribXB(UBNatural attribute) throws XBProcessingException, IOException {
// Process your data
}
@Override
public void dataXB(InputStream data) throws XBProcessingException, IOException {
// Process your data
}
@Override
public void endXB() throws XBProcessingException, IOException {
// Process your data
}
});
reader.read();
reader.close();
} catch (IOException | XBProcessingException ex) {
// Process exception
}
Token Parsers
Variant of parsing using tokens is defined in “org.xbup.lib.core.parser.token” package and provides interfaces with single method handing token value.
XBBeginToken, XBAttributeToken, XBDataToken, XBEndToken
XBTBeginToken, XBTTypeToken, XBTAttributeToken, XBTDataToken, XBTEndToken
You have to process content of data token (for example read InputStream) before receiving next token.
For different ways and directions of handling tokens there are defined interfaces for each case:
XBTEventListener - token stream goes into class and is controlled by sender
XBTEventProducer - token stream goes from class and is controlled by sender
XBTPullConsumer - token stream goes into class and is controlled by receiver
XBTPullProvider - token stream goes from class and is controlled by receiver
And for conversion of binary data to token stream there are corresponding parser classes:
XBTEventReader - binary stream to token stream controlled by sender
XBTEventWriter - token stream to binary stream controlled by sender
XBTPullReader - binary stream to token stream controlled by receiver
XBTPullWriter - token stream to binary stream controlled by receiver
Usage Examples
try (XBEventWriter writer = new XBEventWriter()) {
writer.open(new FileOutputStream("test.xb"));
writer.putXBToken(new XBBeginToken(XBBlockTerminationMode.SIZE_SPECIFIED));
writer.putXBToken(new XBAttributeToken(new UBNat32(1)));
writer.putXBToken(new XBAttributeToken(new UBNat32(2)));
writer.putXBToken(new XBEndToken());
writer.closeXB();
} catch (IOException | XBProcessingException ex) {
// Process exception
}
try {
XBPullReader reader = new XBPullReader();
reader.open(new FileInputStream("test.xb"));
XBBeginToken beginToken = (XBBeginToken) reader.pullXBToken();
XBAttributeToken attribute1Token = (XBAttributeToken) reader.pullXBToken();
XBAttributeToken attribute2Token = (XBAttributeToken) reader.pullXBToken();
XBEndToken endToken = (XBEndToken) reader.pullXBToken();
} catch (IOException | XBProcessingException ex) {
// Process exception
}
Serialization
Several ways how to perform conversion of object data to protocol and in oposite direction are included in “org.xbup.lib.core.serial” package.
There are few subpackages covering various serialization methods:
basic - Serializations using basic parser
token - Serializations using token parser
child - Serialization allowing include other serialized object as child blocks
param - Serialization utilizing block specification and parameters
Streaming
Stream Event Processing
Framework and Catalog Access