Example usage for io.vertx.core.json EncodeException EncodeException

List of usage examples for io.vertx.core.json EncodeException EncodeException

Introduction

In this page you can find the example usage for io.vertx.core.json EncodeException EncodeException.

Prototype

public EncodeException(String message) 

Source Link

Usage

From source file:com.tesco.mewbase.bson.Bson.java

License:Open Source License

public static void encode(Object obj, OutputStream outputStream) throws EncodeException {
    try {/*from   w w  w .  j a  va  2s  . c o  m*/
        mapper.writeValue(outputStream, obj);
    } catch (Exception e) {
        throw new EncodeException("Failed to encode as BSON: " + e.getMessage());
    }
}

From source file:io.techcode.logbulk.pipeline.output.SyslogOutput.java

License:Open Source License

@Override
public Handler<JsonObject> encoder() {
    return data -> {
        Buffer buf = Buffer.buffer();

        // Add facility
        buf.appendString("<");
        String facility = mapping.get(SyslogHeader.FACILITY);
        String severity = mapping.get(SyslogHeader.SEVERITY);
        if (mapping.containsKey(SyslogHeader.FACILITY) && mapping.containsKey(SyslogHeader.SEVERITY)
                && data.containsKey(facility) && data.containsKey(severity)) {
            int acc = data.getInteger(facility) * 8 + data.getInteger(severity);
            buf.appendString(String.valueOf(acc));
        }/*from   w  w w  . j  a  v a 2 s .  c  om*/
        buf.appendString(">1 ");

        // Add timestamp
        populate(buf, SyslogHeader.TIMESTAMP, data);

        // Add hostname
        populate(buf, SyslogHeader.HOST, data);

        // Add application
        populate(buf, SyslogHeader.APPLICATION, data);

        // Add processus
        populate(buf, SyslogHeader.PROCESSUS, data);

        // Add msg id
        populate(buf, SyslogHeader.ID, data);

        // Add structured data
        populate(buf, SyslogHeader.DATA, data);

        // Add message
        String message = mapping.get(SyslogHeader.MESSAGE);
        if (mapping.containsKey(SyslogHeader.MESSAGE)) {
            if (data.containsKey(message)) {
                buf.appendString(String.valueOf(data.getValue(message)));
            } else {
                try {
                    Json.mapper.writeValue(new ByteBufOutputStream(buf.getByteBuf()), data.getMap());
                } catch (Exception e) {
                    throw new EncodeException("Failed to encode as JSON: " + e.getMessage());
                }
            }
        }

        getConnection().write(framing(buf));
    };
}