Composing Bytes Messages

The body of a bytes message simply consists of a stream of uninterpreted
bytes; its interpretation is entirely a matter of agreement between sender
and receiver. This type of message is intended primarily for encoding message
formats required by other existing message systems; Message Queue clients
should generally use one of the other, more specific message types instead.

Composing a bytes message is similar to composing a stream message (see Composing Stream Messages). You create the message
with the session method createBytesMessage, then use the methods shown in Table 2–13 to encode primitive values
into the message’s byte stream: for example,

puts the message body in read-only mode and repositions the byte stream
to the beginning, ready to read (see Processing Messages). Attempting to write further content to a message in this state
will cause an exception (MessageNotWriteableException). The inherited Message method clearBody can be used to delete the entire message body and make it writeable
again.