Example usage for com.fasterxml.jackson.dataformat.cbor CBORParser close

List of usage examples for com.fasterxml.jackson.dataformat.cbor CBORParser close

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.cbor CBORParser close.

Prototype

@Override
    public void close() throws IOException 

Source Link

Usage

From source file:com.pushtechnology.diffusion.examples.runnable.ConsumingJson.java

@Override
public void onStarted(Session session) {
    final Topics topics = session.feature(Topics.class);

    // Add the stream to receive JSON values
    topics.addStream(">json/random", JSON.class, new Topics.ValueStream.Default<JSON>() {
        @Override/*  w  w w .  ja v a2 s. com*/
        public void onValue(String topicPath, TopicSpecification specification, JSON oldValue, JSON newValue) {

            try {
                // Converts a Json map into a Java Map.
                final CBORParser parser = CBOR_FACTORY.createParser(newValue.asInputStream());
                final Map<String, BigInteger> map = OBJECT_MAPPER.readValue(parser, INT_MAP_TYPE);
                parser.close();

                // Log the timestamp from the map
                LOG.info("New timestamp {}", map.get("timestamp"));
            } catch (IOException e) {
                LOG.warn("Failed to transform value '{}'", newValue, e);
            }
        }
    });

    // Subscribe to the topic
    topics.subscribe(">json/random", new Topics.CompletionCallback.Default());
}