INT-3594: Add Another MQTT Converter Constructor

JIRA: https://jira.spring.io/browse/INT-3594

Add a constructor that just takes a `charset`; useful for inbound-only
converters.
This commit is contained in:
Gary Russell
2015-01-05 18:59:19 -05:00
parent 91e7d78884
commit 4e67714ad0

View File

@@ -51,14 +51,49 @@ public class DefaultPahoMessageConverter implements MqttMessageConverter, BeanFa
private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
/**
* Construct a converter with default options (qos=0, retain=false, charset=UTF-8).
*/
public DefaultPahoMessageConverter() {
this (0, false);
}
/**
* Construct a converter to create outbound messages with the supplied default qos and retain settings and
* a UTF-8 charset for converting outbound String paylaods to {@code byte[]} and inbound
* {@code byte[]} to String (unless {@link #setPayloadAsBytes(boolean) payloadAdBytes} is true).
* @param defaultQos the default qos.
* @param defaultRetain the default retain.
*/
public DefaultPahoMessageConverter(int defaultQos, boolean defaultRetain) {
this(defaultQos, defaultRetain, "UTF-8");
}
/**
* Construct a converter with default options (qos=0, retain=false) and
* the supplied charset.
* @param charset the charset used to convert outbound String paylaods to {@code byte[]} and inbound
* {@code byte[]} to String (unless {@link #setPayloadAsBytes(boolean) payloadAdBytes} is true).
* @since 4.1.2
*/
public DefaultPahoMessageConverter(String charset) {
this(0, false, charset);
}
/**
* Construct a converter to create outbound messages with the supplied default qos and retain settings and
* the supplied charset.
* @param defaultQos the default qos.
* @param defaultRetained the default retain.
* @param charset the charset used to convert outbound String paylaods to {@code byte[]} and inbound
* {@code byte[]} to String (unless {@link #setPayloadAsBytes(boolean) payloadAdBytes} is true).
*/
public DefaultPahoMessageConverter(int defaultQos, boolean defaultRetained, String charset) {
this.defaultQos = defaultQos;
this.defaultRetained = defaultRetained;
this.charset = charset;
}
@Override
public final void setBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
@@ -85,12 +120,6 @@ public class DefaultPahoMessageConverter implements MqttMessageConverter, BeanFa
public boolean isPayloadAsBytes() {
return this.payloadAsBytes;
}
public DefaultPahoMessageConverter(int defaultQos, boolean defaultRetained, String charset) {
this.defaultQos = defaultQos;
this.defaultRetained = defaultRetained;
this.charset = charset;
}
@Override
public Message<?> toMessage(Object mqttMessage, MessageHeaders headers) {