當前位置: 首頁>>代碼示例>>Java>>正文


Java BytesMessage.getStringProperty方法代碼示例

本文整理匯總了Java中javax.jms.BytesMessage.getStringProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java BytesMessage.getStringProperty方法的具體用法?Java BytesMessage.getStringProperty怎麽用?Java BytesMessage.getStringProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jms.BytesMessage的用法示例。


在下文中一共展示了BytesMessage.getStringProperty方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convertFromBytesMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * Convert a BytesMessage to a Java Object with the specified type.
 * @param message the input message
 * @param targetJavaType the target type
 * @return the message converted to an object
 * @throws JMSException if thrown by JMS
 * @throws IOException in case of I/O errors
 */
protected Object convertFromBytesMessage(BytesMessage message, JavaType targetJavaType)
		throws JMSException, IOException {

	String encoding = this.encoding;
	if (this.encodingPropertyName != null && message.propertyExists(this.encodingPropertyName)) {
		encoding = message.getStringProperty(this.encodingPropertyName);
	}
	byte[] bytes = new byte[(int) message.getBodyLength()];
	message.readBytes(bytes);
	try {
		String body = new String(bytes, encoding);
		return this.objectMapper.readValue(body, targetJavaType);
	}
	catch (UnsupportedEncodingException ex) {
		throw new MessageConversionException("Cannot convert bytes to String", ex);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:MappingJackson2MessageConverter.java

示例2: getPayloadFromBytesMessage

import javax.jms.BytesMessage; //導入方法依賴的package包/類
/**
 * Convert a BytesMessage to a Java Object with the specified type.
 * @param message the input message
 * @return the message body
 * @throws JMSException if thrown by JMS
 * @throws IOException in case of I/O errors
 */
protected String getPayloadFromBytesMessage(BytesMessage message) throws JMSException, IOException {

    String encoding = this.encoding;
    if (this.encodingPropertyName != null && message.propertyExists(this.encodingPropertyName)) {
        encoding = message.getStringProperty(this.encodingPropertyName);
    }
    byte[] bytes = new byte[(int) message.getBodyLength()];
    message.readBytes(bytes);
    try {
        return new String(bytes, encoding);
    } catch (UnsupportedEncodingException ex) {
        throw new MessageConversionException("Cannot convert bytes to String", ex);
    }
}
 
開發者ID:kinglcc,項目名稱:spring-boot-jms,代碼行數:22,代碼來源:Jackson2JmsMessageConverter.java


注:本文中的javax.jms.BytesMessage.getStringProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。