All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.quotemedia.streamer.client.impl.TextPayloadEncoder Maven / Gradle / Ivy

package com.quotemedia.streamer.client.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.quotemedia.streamer.messages.Encodings;
import com.quotemedia.streamer.messages.MimeTypes;
import com.quotemedia.streamer.messages.control.CtrlMessage;

import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;

public class TextPayloadEncoder implements PayloadEncoder {
    private final ObjectMapper json;

    public TextPayloadEncoder(final ObjectMapper json) {
        this.json = checkNotNull(json);
    }

    @Override
    public MessageImpl encode(final CtrlMessage data) throws IOException {
        final String payload = this.json.writeValueAsString(data);
        final MessageImpl msg = new MessageImpl();
        msg.timestamp(System.currentTimeMillis());
        msg.encoding(Encodings.NONE_CHAR);
        msg.mimetype(MimeTypes.JSON_CHAR);
        msg.payload(payload);
        return msg;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy