JMSBytesMessage

 

public class JMSBytesMessage
extends JMSMessage
implements BytesMessage

java.lang.Object
   |
   +----com.ibm.jms.JMSMessage
           |
           +----com.ibm.jms.JMSBytesMessage
          

JMSBytesMessage is used to send a message containing a stream of uninterpreted bytes. The receiver of the message supplies the interpretation of the bytes.

Its methods are based largely on those found in java.io.DataInputStream and java.io.DataOutputStream.

This message type is for client encoding of existing message formats. If possible, use one of the other self-defining message types instead.

Although JMS allows the use of message properties with byte messages, it is typically not done since the inclusion of properties affects the format.

The primitive types can be written explicitly using methods for each type; this is the recommended method. They can also be written generically as objects. For example, a call to BytesMessage.writeInt(6) is equivalent to BytesMessage.writeObject(new Integer(6)). Both forms are provided because the explicit form is convenient for static programming and the object form is needed when types are not known at compile time.

When the message is first created, and when clearBody() is called, the body of the message is in write-only mode. After the first call to the reset method has been made, the message is in read-only mode. When a message has been sent, the provider always calls reset to read its content. Likewise, when a message has been received, the provider calls reset so that the message is in read-only mode for the client.

If clearBody is called on a message in read-only mode, the message body is cleared and the message is in write-only mode.

If a client attempts to read a message in write-only mode, a MessageNotReadableException is thrown.

If a client attempts to write a message in read-only mode, a MessageNotWriteableException is thrown.

JMSBytesMessage can be used by a JMS application to read or write a message that is sent to or from a non-Java application. As this non-Java application might be hosted on a platform with different integer or floating point encoding conventions, JMSBytesMessage class includes routines to represent its numeric data types in a number of different ways.

The only character set supported by JMSBytesMessage is the Java™ version of UTF-8. This includes a two-byte length prefix, and is limited to strings less than 65536 bytes in long. Applications wanting to send a string in different character set have a choice of two methods:

  1. Send the message as a JMSTextMessage - if it is entirely made up of strings.

  2. Convert the String to a byte array and then write it into JMSBytesMessage using the writeBytes() method.

The type of numeric encoding to be used can be set by the transport code when importing or exporting the message as a byte array. The type of encoding is specified using an int, which is effectively the sum of two separate enums, as defined by the ENC_* fields. This follows the convention laid down by WebSphere MQ in the MQMD.encoding field. For convenience, the constants defined here take precisely the same values as their MQENC counterparts defined in com.ibm.mq.MQC.


uj25810_