public final class StreamMessage extends Message implements jakarta.jms.StreamMessage
jakarta.jms.StreamMessage
interface.Modifier and Type | Field and Description |
---|---|
private int |
available |
private static int |
BOOLEAN |
private static int |
BYTE |
private static int |
BYTES |
private static int |
CHAR |
private static int |
DOUBLE |
private boolean |
firstTimeBytesRead |
private static int |
FLOAT |
private DataInputStream |
inputStream
The stream for reading the data.
|
private static int |
INT |
private static int |
LONG |
private static int |
NULL |
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 modification. |
private static int |
SHORT |
private static int |
STRING |
Constructor and Description |
---|
StreamMessage()
Instantiates a bright new
StreamMessage . |
StreamMessage(Session session,
Message momMsg)
Instantiates a
StreamMessage wrapping a consumed
MOM message containing a stream of bytes. |
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.
|
protected <T> T |
getEffectiveBody(Class<T> c)
Get message body
|
boolean |
isBodyAssignableTo(Class c)
API 2.0 method
|
protected void |
prepare()
Method actually preparing the message for sending by transferring the
local body into the wrapped MOM message.
|
private void |
prepareWrite()
Internal method called before each writing operation.
|
boolean |
readBoolean()
API method.
|
byte |
readByte()
API method.
|
int |
readBytes(byte[] bytes)
API method.
|
char |
readChar()
API method.
|
double |
readDouble()
API method.
|
float |
readFloat()
API method.
|
int |
readInt()
API method.
|
long |
readLong()
API method.
|
Object |
readObject()
API method.
|
short |
readShort()
API method.
|
String |
readString()
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 |
writeString(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, 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, wrapMomMessage
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
acknowledge, clearProperties, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDeliveryTime, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, propertyExists, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDeliveryTime, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty
private 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 modification.private transient int available
private transient boolean firstTimeBytesRead
private static final int SHORT
private static final int CHAR
private static final int INT
private static final int LONG
private static final int FLOAT
private static final int DOUBLE
private static final int BOOLEAN
private static final int STRING
private static final int BYTE
private static final int BYTES
private static final int NULL
StreamMessage() throws jakarta.jms.JMSException
StreamMessage
.jakarta.jms.JMSException
- In case of an error while creating the output
stream.StreamMessage(Session session, Message momMsg) throws jakarta.jms.JMSException
StreamMessage
wrapping a consumed
MOM message containing a stream of bytes.session
- The consuming session.momMsg
- The MOM message to wrap.jakarta.jms.JMSException
- In case of an error while creating the input
stream.public <T> T getBody(Class<T> c) throws jakarta.jms.JMSException
Message
getBody
in interface jakarta.jms.Message
getBody
in class Message
c
- 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.public boolean isBodyAssignableTo(Class c) throws jakarta.jms.JMSException
Message
isBodyAssignableTo
in interface jakarta.jms.Message
isBodyAssignableTo
in class Message
c
- the specified type
Check if the message body is capable of being assigned to specified typejakarta.jms.JMSException
- if fail to return a value due to some internal errorprotected <T> T getEffectiveBody(Class<T> c) throws jakarta.jms.JMSException
getEffectiveBody
in class Message
c
- 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.public 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.
private void prepareWrite() throws jakarta.jms.JMSException
jakarta.jms.MessageNotWriteableException
- If the message body is READ only.jakarta.jms.JMSException
- If the stream could not be prepared for the
writing operation.public void writeBoolean(boolean value) throws jakarta.jms.JMSException
writeBoolean
in interface jakarta.jms.StreamMessage
value
- 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.StreamMessage
value
- 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
Each byte array is written to the message as a separate byte array field. Consecutively written byte array fields are treated as distinct fields when the fields are read.
writeBytes
in interface jakarta.jms.StreamMessage
value
- 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
The portion of the byte array is written to the message as a separate byte array field. Consecutively written byte array fields are treated as distinct fields when the fields are read.
writeBytes
in interface jakarta.jms.StreamMessage
value
- 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.StreamMessage
value
- 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.StreamMessage
value
- 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.StreamMessage
value
- 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.StreamMessage
value
- 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.StreamMessage
value
- 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.StreamMessage
value
- 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 writeString(String value) throws jakarta.jms.JMSException
writeString
in interface jakarta.jms.StreamMessage
value
- 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 writeObject(Object value) throws jakarta.jms.JMSException
writeObject
in interface jakarta.jms.StreamMessage
value
- the value to be written.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.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic byte readByte() throws jakarta.jms.JMSException
readByte
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic short readShort() throws jakarta.jms.JMSException
readShort
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic char readChar() throws jakarta.jms.JMSException
readChar
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic int readInt() throws jakarta.jms.JMSException
readInt
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic long readLong() throws jakarta.jms.JMSException
readLong
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic float readFloat() throws jakarta.jms.JMSException
readFloat
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic double readDouble() throws jakarta.jms.JMSException
readDouble
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic int readBytes(byte[] bytes) throws jakarta.jms.JMSException
To read the field value, readBytes should be successively called until it returns a value less than the length of the read buffer. The value of the bytes in the buffer following the last byte read is undefined. If readBytes returns a value equal to the length of the buffer, a subsequent readBytes call must be made. If there are no more bytes to be read, this call returns -1.
If the byte array field value is null, readBytes returns -1.
If the byte array field value is empty, readBytes returns 0.
Once the first readBytes call on a byte[] field value has been made, the full value of the field must be read before it is valid to read the next field. An attempt to read the next field before that has been done will throw a MessageFormatException.
To read the byte field value into a new byte[] object, use the readObject method.
readBytes
in interface jakarta.jms.StreamMessage
bytes
- the buffer into which the data is read.jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic String readString() throws jakarta.jms.JMSException
readString
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the expected type is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic Object readObject() throws jakarta.jms.JMSException
readObject
in interface jakarta.jms.StreamMessage
jakarta.jms.MessageNotReadableException
- If the message body is write-only.jakarta.jms.MessageFormatException
- If reading the body is
not possible.jakarta.jms.MessageEOFException
- Unexpected end of bytes array.jakarta.jms.JMSException
- internal errorpublic void reset() throws jakarta.jms.JMSException
reset
in interface jakarta.jms.StreamMessage
jakarta.jms.JMSException
- If an error occurs while closing the output
stream.protected void prepare() throws jakarta.jms.JMSException
Copyright © 2023 ScalAgent D.T.. All rights reserved.