Handling a byte-based message

Sometimes it is necessary to send an unformatted stream of bytes as a message. This recipe illustrates this process using the BytesMessage interface. However, when possible, other message types such as string and objects should be used.

The advantages of using an unformatted stream of bytes include ease of read and write operations and a fixed size message. When data is written or read using the BytesMessage methods, it is stored using the appropriate primitive data format. For example, when an integer is written, it will be stored as a 32-bit two's complement number. The size of the number will always be four bytes regardless of the number of digits comprising the number.

Getting ready

The essential structure of a ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.