public final class BytesMessage extends Message implements jakarta.jms.BytesMessage
jakarta.jms.BytesMessage interface.
A BytesMessage object is used to send a message containing a stream of uninterpreted bytes. It inherits from the Message interface and adds a bytes message body. The BytesMessage methods are based largely on those found in java.io.DataInputStream and java.io.DataOutputStream.
The primitive types can be written explicitly using methods for each type. They may also be written generically as objects. For instance, a call to BytesMessage.writeInt(6) is equivalent to BytesMessage.writeObject(new Integer(6)).
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 reset has been made, the message body is in read-only mode. After a message has been sent, the client that sent it can retain and modify it without affecting the message that has been sent. The same message object can be sent multiple times. When a message has been received, the provider has called reset so that the message body 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.
| Modifier and Type | Field and Description |
|---|---|
private DataInputStream |
inputStream
The stream for reading the written data.
|
private ByteArrayOutputStream |
outputBuffer
The array in which the written data is buffered.
|
private DataOutputStream |
outputStream
The stream in which body data is written.
|
private boolean |
prepared
true if the message has been sent since its last modif. |
| Constructor and Description |
|---|
BytesMessage()
Instantiates a bright new
BytesMessage. |
BytesMessage(Session sess,
org.objectweb.joram.shared.messages.Message momMsg)
Instantiates a
BytesMessage wrapping a consumed
MOM message containing a bytes array. |
| Modifier and Type | Method and Description |
|---|---|
void |
clearBody()
API method.
|
<T> T |
getBody(Class<T> c)
Returns the message body as an object of the specified type.
|
long |
getBodyLength()
API method.
|
(package private) byte[] |
getBytes()
Get message content as byte array
|
protected <T> T |
getEffectiveBody(Class<T> c)
Get message body
|
protected void |
prepare()
Method actually preparing the message for sending by transfering the
local body into the wrapped MOM message.
|
boolean |
readBoolean()
API method.
|
byte |
readByte()
API method.
|
int |
readBytes(byte[] value)
API method.
|
int |
readBytes(byte[] value,
int length)
API method.
|
char |
readChar()
API method.
|
double |
readDouble()
API method.
|
float |
readFloat()
API method.
|
int |
readInt()
API method.
|
long |
readLong()
API method.
|
short |
readShort()
API method.
|
int |
readUnsignedByte()
API method.
|
int |
readUnsignedShort()
API method.
|
String |
readUTF()
API method.
|
void |
reset()
API method.
|
void |
writeBoolean(boolean value)
API method.
|
void |
writeByte(byte value)
API method.
|
void |
writeBytes(byte[] value)
API method.
|
void |
writeBytes(byte[] value,
int offset,
int length)
API method.
|
void |
writeChar(char value)
API method.
|
void |
writeDouble(double value)
API method.
|
void |
writeFloat(float value)
API method.
|
void |
writeInt(int value)
API method.
|
void |
writeLong(long value)
API method.
|
void |
writeObject(Object value)
API method.
|
void |
writeShort(short value)
API method.
|
void |
writeUTF(String value)
API method.
|
acknowledge, clearProperties, convertJMSMessage, dumpBody, dumpBody, getBooleanProperty, getByteProperty, getCompressedMinSize, getCompressionLevel, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDeliveryTime, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getMomMsg, getObjectProperty, getProperties, getPropertyNames, getRawBody, getShortProperty, getStringProperty, isBodyAssignableTo, isCompressed, prepareJMSMessage, propertyExists, resetPropertiesRO, setBooleanProperty, setByteProperty, setCompressedMinSize, setCompressionLevel, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDeliveryTime, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty, toString, toString, wrapMomMessageclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitacknowledge, clearProperties, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDeliveryTime, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, isBodyAssignableTo, propertyExists, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDeliveryTime, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringPropertyprivate transient ByteArrayOutputStream outputBuffer
private transient DataOutputStream outputStream
private transient DataInputStream inputStream
private transient boolean prepared
true if the message has been sent since its last modif.BytesMessage()
BytesMessage.BytesMessage(Session sess, org.objectweb.joram.shared.messages.Message momMsg) throws jakarta.jms.JMSException
BytesMessage wrapping a consumed
MOM message containing a bytes array.sess - The consuming session.momMsg - The MOM message to wrap.jakarta.jms.JMSException - if an error has occurredpublic long getBodyLength()
throws jakarta.jms.JMSException
getBodyLength in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message is WRITE-ONLY.jakarta.jms.JMSExceptionpublic void clearBody()
throws jakarta.jms.JMSException
Calling this method leaves the message body in the same state as an empty body in a newly created message.
public void writeBoolean(boolean value)
throws jakarta.jms.JMSException
writeBoolean in interface jakarta.jms.BytesMessagevalue - the value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeByte(byte value)
throws jakarta.jms.JMSException
writeByte in interface jakarta.jms.BytesMessagevalue - the value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeBytes(byte[] value)
throws jakarta.jms.JMSException
writeBytes in interface jakarta.jms.BytesMessagevalue - the byte array to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeBytes(byte[] value,
int offset,
int length)
throws jakarta.jms.JMSException
writeBytes in interface jakarta.jms.BytesMessagevalue - the byte array to be written.offset - the initial offset within the byte arraylength - the number of bytes to usejakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeChar(char value)
throws jakarta.jms.JMSException
writeChar in interface jakarta.jms.BytesMessagevalue - the value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeDouble(double value)
throws jakarta.jms.JMSException
writeDouble in interface jakarta.jms.BytesMessagevalue - the value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeFloat(float value)
throws jakarta.jms.JMSException
writeFloat in interface jakarta.jms.BytesMessagevalue - the value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeInt(int value)
throws jakarta.jms.JMSException
writeInt in interface jakarta.jms.BytesMessagevalue - the value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeLong(long value)
throws jakarta.jms.JMSException
writeLong in interface jakarta.jms.BytesMessagevalue - the value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeShort(short value)
throws jakarta.jms.JMSException
writeShort in interface jakarta.jms.BytesMessagevalue - the value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeUTF(String value) throws jakarta.jms.JMSException
writeUTF in interface jakarta.jms.BytesMessagevalue - the String value to be written.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.JMSException - If the value could not be written on the stream.public void writeObject(Object value) throws jakarta.jms.JMSException
This method works only for the objectified primitive object types (Integer, Double, Long ...), String objects, and byte arrays.
writeObject in interface jakarta.jms.BytesMessagevalue - the primitive Java object to be written; it must not be null.jakarta.jms.MessageNotWriteableException - If the message body is read-only.jakarta.jms.MessageFormatException - If the value type is invalid.jakarta.jms.JMSException - If the value could not be written on the stream.public boolean readBoolean()
throws jakarta.jms.JMSException
readBoolean in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public byte readByte()
throws jakarta.jms.JMSException
readByte in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public int readUnsignedByte()
throws jakarta.jms.JMSException
readUnsignedByte in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public short readShort()
throws jakarta.jms.JMSException
readShort in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public int readUnsignedShort()
throws jakarta.jms.JMSException
readUnsignedShort in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public char readChar()
throws jakarta.jms.JMSException
readChar in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public int readInt()
throws jakarta.jms.JMSException
readInt in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public long readLong()
throws jakarta.jms.JMSException
readLong in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public float readFloat()
throws jakarta.jms.JMSException
readFloat in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public double readDouble()
throws jakarta.jms.JMSException
readDouble in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public int readBytes(byte[] value)
throws jakarta.jms.JMSException
A return value of the total number of bytes read less than the length of the array indicates that there are no more bytes left to be read from the stream. The next read of the stream returns -1.
readBytes in interface jakarta.jms.BytesMessagevalue - the buffer into which the data is read.jakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public int readBytes(byte[] value,
int length)
throws jakarta.jms.JMSException
A return value of the total number of bytes read less than the length parameter indicates that there are no more bytes left to be read from the stream. The next read of the stream returns -1.
If length is negative, or length is greater than the length of the array value, then an IndexOutOfBoundsException is thrown. No bytes will be read from the stream for this exception case.
readBytes in interface jakarta.jms.BytesMessagevalue - the buffer into which the data is read.length - the number of bytes to read; must be less than or equal to value.length.jakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public String readUTF() throws jakarta.jms.JMSException
readUTF in interface jakarta.jms.BytesMessagejakarta.jms.MessageNotReadableException - If the message body is write-only.jakarta.jms.JMSException - If an exception occurs while reading the bytes.public void reset()
throws jakarta.jms.JMSException
reset in interface jakarta.jms.BytesMessagejakarta.jms.JMSException - If an error occurs while closing the output
stream.protected void prepare()
throws jakarta.jms.JMSException
byte[] getBytes()
throws jakarta.jms.JMSException
jakarta.jms.JMSException - If an error occurs while closing the output stream.public <T> T getBody(Class<T> c) throws jakarta.jms.JMSException
MessagegetBody in interface jakarta.jms.MessagegetBody in class Messagec - The type to which the message body will be assigned.
If the message has no body then any type may be specified and null is returned.
TextMessage then this parameter must
be set to String.class or another type to which
a String is assignable.
ObjectMessage then parameter must
be set to java.io.Serializable.class or
another type to which the body is assignable.
MapMessage then this parameter must
be set to java.util.Map.class (or java.lang.Object.class).
BytesMessage then this parameter must
be set to byte[].class (or java.lang.Object.class). This method
will reset the BytesMessage before and after use.
TextMessage, ObjectMessage, MapMessage
or BytesMessage and the message has no body,
then the above does not apply and this parameter may be set to any type;
the returned value will always be null.
Message (but not one of its subtypes)
then this parameter may be set to any type;
the returned value will always be null.jakarta.jms.MessageFormatException - if the message is a StreamMessage, if the message body cannot be
assigned to the specified type, or if the message is an ObjectMessage and object deserialization fails.jakarta.jms.JMSException - if the JMS provider fails to get the message body due to some internal error.protected <T> T getEffectiveBody(Class<T> c) throws jakarta.jms.JMSException
MessagegetEffectiveBody in class Messagec - The type to which the message body will be assigned.jakarta.jms.JMSException - if the JMS provider fails to return a value due to some internal error.Copyright © 2023 ScalAgent D.T.. All rights reserved.