Class StreamMessage
- java.lang.Object
-
- org.ow2.joram.jakarta.jms.Message
-
- org.ow2.joram.jakarta.jms.StreamMessage
-
- All Implemented Interfaces:
jakarta.jms.Message,jakarta.jms.StreamMessage
public final class StreamMessage extends Message implements jakarta.jms.StreamMessage
Implements thejakarta.jms.StreamMessageinterface.
-
-
Field Summary
Fields Modifier and Type Field Description private intavailableprivate static intBOOLEANprivate static intBYTEprivate static intBYTESprivate static intCHARprivate static intDOUBLEprivate booleanfirstTimeBytesReadprivate static intFLOATprivate DataInputStreaminputStreamThe stream for reading the data.private static intINTprivate static intLONGprivate static intNULLprivate ByteArrayOutputStreamoutputBufferThe array in which the written data is buffered.private DataOutputStreamoutputStreamThe stream in which body data is written.private booleanpreparedtrueif the message has been sent since its last modification.private static intSHORTprivate static intSTRING
-
Constructor Summary
Constructors Constructor Description StreamMessage()Instantiates a bright newStreamMessage.StreamMessage(Session session, Message momMsg)Instantiates aStreamMessagewrapping a consumed MOM message containing a stream of bytes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearBody()API method.<T> TgetBody(Class<T> c)Returns the message body as an object of the specified type.protected <T> TgetEffectiveBody(Class<T> c)Get message bodybooleanisBodyAssignableTo(Class c)API 2.0 methodprotected voidprepare()Method actually preparing the message for sending by transferring the local body into the wrapped MOM message.private voidprepareWrite()Internal method called before each writing operation.booleanreadBoolean()API method.bytereadByte()API method.intreadBytes(byte[] bytes)API method.charreadChar()API method.doublereadDouble()API method.floatreadFloat()API method.intreadInt()API method.longreadLong()API method.ObjectreadObject()API method.shortreadShort()API method.StringreadString()API method.voidreset()API method.voidwriteBoolean(boolean value)API method.voidwriteByte(byte value)API method.voidwriteBytes(byte[] value)API method.voidwriteBytes(byte[] value, int offset, int length)API method.voidwriteChar(char value)API method.voidwriteDouble(double value)API method.voidwriteFloat(float value)API method.voidwriteInt(int value)API method.voidwriteLong(long value)API method.voidwriteObject(Object value)API method.voidwriteShort(short value)API method.voidwriteString(String value)API method.-
Methods inherited from class org.ow2.joram.jakarta.jms.Message
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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jakarta.jms.Message
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
-
-
-
-
Field Detail
-
outputBuffer
private transient ByteArrayOutputStream outputBuffer
The array in which the written data is buffered.
-
outputStream
private transient DataOutputStream outputStream
The stream in which body data is written.
-
inputStream
private transient DataInputStream inputStream
The stream for reading the data.
-
prepared
private transient boolean prepared
trueif the message has been sent since its last modification.
-
available
private transient int available
-
firstTimeBytesRead
private transient boolean firstTimeBytesRead
-
SHORT
private static final int SHORT
- See Also:
- Constant Field Values
-
CHAR
private static final int CHAR
- See Also:
- Constant Field Values
-
INT
private static final int INT
- See Also:
- Constant Field Values
-
LONG
private static final int LONG
- See Also:
- Constant Field Values
-
FLOAT
private static final int FLOAT
- See Also:
- Constant Field Values
-
DOUBLE
private static final int DOUBLE
- See Also:
- Constant Field Values
-
BOOLEAN
private static final int BOOLEAN
- See Also:
- Constant Field Values
-
STRING
private static final int STRING
- See Also:
- Constant Field Values
-
BYTE
private static final int BYTE
- See Also:
- Constant Field Values
-
BYTES
private static final int BYTES
- See Also:
- Constant Field Values
-
NULL
private static final int NULL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StreamMessage
StreamMessage() throws jakarta.jms.JMSExceptionInstantiates a bright newStreamMessage.- Throws:
jakarta.jms.JMSException- In case of an error while creating the output stream.
-
StreamMessage
StreamMessage(Session session, Message momMsg) throws jakarta.jms.JMSException
Instantiates aStreamMessagewrapping a consumed MOM message containing a stream of bytes.- Parameters:
session- The consuming session.momMsg- The MOM message to wrap.- Throws:
jakarta.jms.JMSException- In case of an error while creating the input stream.
-
-
Method Detail
-
getBody
public <T> T getBody(Class<T> c) throws jakarta.jms.JMSException
Description copied from class:MessageReturns the message body as an object of the specified type. This method may be called on any type of message except for StreamMessage. The message body must be capable of being assigned to the specified type. This means that the specified class or interface must be either the same as, or a superclass or superinterface of, the class of the message body.- Specified by:
getBodyin interfacejakarta.jms.Message- Overrides:
getBodyin classMessage- Parameters:
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.
If the message is aTextMessagethen this parameter must be set toString.classor another type to which aStringis assignable.
If the message is aObjectMessagethen parameter must be set tojava.io.Serializable.classor another type to which the body is assignable.
If the message is aMapMessagethen this parameter must be set tojava.util.Map.class(orjava.lang.Object.class).
If the message is aBytesMessagethen this parameter must be set tobyte[].class(orjava.lang.Object.class). This method will reset theBytesMessagebefore and after use.
If the message is aTextMessage,ObjectMessage,MapMessageorBytesMessageand 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.
If the message is aMessage(but not one of its subtypes) then this parameter may be set to any type; the returned value will always be null.- Returns:
- the message body
- Throws:
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.
-
isBodyAssignableTo
public boolean isBodyAssignableTo(Class c) throws jakarta.jms.JMSException
Description copied from class:MessageAPI 2.0 method- Specified by:
isBodyAssignableToin interfacejakarta.jms.Message- Overrides:
isBodyAssignableToin classMessage- Parameters:
c- the specified type Check if the message body is capable of being assigned to specified type- Returns:
- true if Message is TextMessage or MapMessage, or BytesMessage, or ObjectMessage when it's deserializable false otherwise
- Throws:
jakarta.jms.JMSException- if fail to return a value due to some internal error
-
getEffectiveBody
protected <T> T getEffectiveBody(Class<T> c) throws jakarta.jms.JMSException
Get message body- Overrides:
getEffectiveBodyin classMessage- Parameters:
c- - The type to which the message body will be assigned.- Returns:
- message body
- Throws:
jakarta.jms.JMSException- if the JMS provider fails to return a value due to some internal error.
-
clearBody
public void clearBody() throws jakarta.jms.JMSExceptionAPI method. Clears out the message body.Calling this method leaves the message body in the same state as an empty body in a newly created message.
-
prepareWrite
private void prepareWrite() throws jakarta.jms.JMSExceptionInternal method called before each writing operation.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is READ only.jakarta.jms.JMSException- If the stream could not be prepared for the writing operation.
-
writeBoolean
public void writeBoolean(boolean value) throws jakarta.jms.JMSExceptionAPI method. Writes a boolean to the stream message as a 1-byte value. The value true is written as the value 1; the value false is written as the value 0.- Specified by:
writeBooleanin interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeByte
public void writeByte(byte value) throws jakarta.jms.JMSExceptionAPI method. Writes a byte to the stream message.- Specified by:
writeBytein interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeBytes
public void writeBytes(byte[] value) throws jakarta.jms.JMSExceptionAPI method. Writes a byte array to the StreamMessage.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.
- Specified by:
writeBytesin interfacejakarta.jms.StreamMessage- Parameters:
value- the byte array to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeBytes
public void writeBytes(byte[] value, int offset, int length) throws jakarta.jms.JMSExceptionAPI method. Writes a portion of a byte array to the StreamMessage.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.
- Specified by:
writeBytesin interfacejakarta.jms.StreamMessage- Parameters:
value- the byte array to be written.offset- the initial offset within the byte arraylength- the number of bytes to use- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeChar
public void writeChar(char value) throws jakarta.jms.JMSExceptionAPI method. Writes a char to the stream message.- Specified by:
writeCharin interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeDouble
public void writeDouble(double value) throws jakarta.jms.JMSExceptionAPI method. Writes a double to the stream message.- Specified by:
writeDoublein interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeFloat
public void writeFloat(float value) throws jakarta.jms.JMSExceptionAPI method. Writes a float to the stream message.- Specified by:
writeFloatin interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeInt
public void writeInt(int value) throws jakarta.jms.JMSExceptionAPI method. Writes an int to the stream message.- Specified by:
writeIntin interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeLong
public void writeLong(long value) throws jakarta.jms.JMSExceptionAPI method. Writes a long to the stream message.- Specified by:
writeLongin interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeShort
public void writeShort(short value) throws jakarta.jms.JMSExceptionAPI method. Writes a short to the stream message.- Specified by:
writeShortin interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeString
public void writeString(String value) throws jakarta.jms.JMSException
API method. Writes a String to the stream message.- Specified by:
writeStringin interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
jakarta.jms.MessageNotWriteableException- If the message body is read-only.jakarta.jms.JMSException- If the value could not be written on the stream.
-
writeObject
public void writeObject(Object value) throws jakarta.jms.JMSException
API method. Writes an object to the stream message. This method works only for the objectified primitive object types (Integer, Double, LongĀ ...), String objects, and byte arrays.- Specified by:
writeObjectin interfacejakarta.jms.StreamMessage- Parameters:
value- the value to be written.- Throws:
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.
-
readBoolean
public boolean readBoolean() throws jakarta.jms.JMSExceptionAPI method. Reads a boolean from the StreamMessage.- Specified by:
readBooleanin interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
readByte
public byte readByte() throws jakarta.jms.JMSExceptionAPI method. Reads a byte from the StreamMessage.- Specified by:
readBytein interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
readShort
public short readShort() throws jakarta.jms.JMSExceptionAPI method. Reads a short from the StreamMessage.- Specified by:
readShortin interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
readChar
public char readChar() throws jakarta.jms.JMSExceptionAPI method. Reads a char from the StreamMessage.- Specified by:
readCharin interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
readInt
public int readInt() throws jakarta.jms.JMSExceptionAPI method. Reads an int from the StreamMessage.- Specified by:
readIntin interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
readLong
public long readLong() throws jakarta.jms.JMSExceptionAPI method. Reads a long from the StreamMessage.- Specified by:
readLongin interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
readFloat
public float readFloat() throws jakarta.jms.JMSExceptionAPI method. Reads a float from the StreamMessage.- Specified by:
readFloatin interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
readDouble
public double readDouble() throws jakarta.jms.JMSExceptionAPI method. Reads a double from the StreamMessage.- Specified by:
readDoublein interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
readBytes
public int readBytes(byte[] bytes) throws jakarta.jms.JMSExceptionAPI method. Reads a byte array from the StreamMessage into the specified buffer.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.
- Specified by:
readBytesin interfacejakarta.jms.StreamMessage- Parameters:
bytes- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or -1 if there is no more data because the end of the byte field has been reached.
- Throws:
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 error
-
readString
public String readString() throws jakarta.jms.JMSException
API method. Reads a String from the StreamMessage.- Specified by:
readStringin interfacejakarta.jms.StreamMessage- Returns:
- a Unicode string from the SreamMessage.
- Throws:
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 error
-
readObject
public Object readObject() throws jakarta.jms.JMSException
API method. Reads an objectified primitive type from the StreamMessage.- Specified by:
readObjectin interfacejakarta.jms.StreamMessage- Returns:
- the value read.
- Throws:
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 error
-
reset
public void reset() throws jakarta.jms.JMSExceptionAPI method. Puts the message body in read-only mode and reset the stream to the beginning.- Specified by:
resetin interfacejakarta.jms.StreamMessage- Throws:
jakarta.jms.JMSException- If an error occurs while closing the output stream.
-
prepare
protected void prepare() throws jakarta.jms.JMSExceptionMethod actually preparing the message for sending by transferring the local body into the wrapped MOM message.
-
-