Class StreamMessage
- java.lang.Object
-
- org.objectweb.joram.client.jms.Message
-
- org.objectweb.joram.client.jms.StreamMessage
-
- All Implemented Interfaces:
Message,StreamMessage
public final class StreamMessage extends Message implements StreamMessage
Implements thejavax.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-
Fields inherited from class org.objectweb.joram.client.jms.Message
jmsDest, logger, momMsg, propertiesRO, RObody, session
-
Fields inherited from interface javax.jms.Message
DEFAULT_DELIVERY_DELAY, DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE
-
-
Constructor Summary
Constructors Constructor Description StreamMessage()Instantiates a bright newStreamMessage.StreamMessage(Session session, org.objectweb.joram.shared.messages.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.objectweb.joram.client.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 javax.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 JMSExceptionInstantiates a bright newStreamMessage.- Throws:
JMSException- In case of an error while creating the output stream.
-
StreamMessage
StreamMessage(Session session, org.objectweb.joram.shared.messages.Message momMsg) throws JMSException
Instantiates aStreamMessagewrapping a consumed MOM message containing a stream of bytes.- Parameters:
session- The consuming session.momMsg- The MOM message to wrap.- Throws:
JMSException- In case of an error while creating the input stream.
-
-
Method Detail
-
getBody
public <T> T getBody(Class<T> c) throws 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 interfaceMessage- 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:
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.JMSException- if the JMS provider fails to get the message body due to some internal error.
-
isBodyAssignableTo
public boolean isBodyAssignableTo(Class c) throws JMSException
Description copied from class:MessageAPI 2.0 method- Specified by:
isBodyAssignableToin interfaceMessage- 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:
JMSException- if fail to return a value due to some internal error
-
getEffectiveBody
protected <T> T getEffectiveBody(Class<T> c) throws JMSException
Get message body- Overrides:
getEffectiveBodyin classMessage- Parameters:
c- - The type to which the message body will be assigned.- Returns:
- message body
- Throws:
JMSException- if the JMS provider fails to return a value due to some internal error.
-
clearBody
public void clearBody() throws 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.
- Specified by:
clearBodyin interfaceMessage- Overrides:
clearBodyin classMessage- Throws:
JMSException- In case of an error while closing the input or output streams.
-
prepareWrite
private void prepareWrite() throws JMSExceptionInternal method called before each writing operation.- Throws:
MessageNotWriteableException- If the message body is READ only.JMSException- If the stream could not be prepared for the writing operation.
-
writeBoolean
public void writeBoolean(boolean value) throws 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 interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeByte
public void writeByte(byte value) throws JMSExceptionAPI method. Writes a byte to the stream message.- Specified by:
writeBytein interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeBytes
public void writeBytes(byte[] value) throws 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 interfaceStreamMessage- Parameters:
value- the byte array to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeBytes
public void writeBytes(byte[] value, int offset, int length) throws 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 interfaceStreamMessage- Parameters:
value- the byte array to be written.offset- the initial offset within the byte arraylength- the number of bytes to use- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeChar
public void writeChar(char value) throws JMSExceptionAPI method. Writes a char to the stream message.- Specified by:
writeCharin interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeDouble
public void writeDouble(double value) throws JMSExceptionAPI method. Writes a double to the stream message.- Specified by:
writeDoublein interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeFloat
public void writeFloat(float value) throws JMSExceptionAPI method. Writes a float to the stream message.- Specified by:
writeFloatin interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeInt
public void writeInt(int value) throws JMSExceptionAPI method. Writes an int to the stream message.- Specified by:
writeIntin interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeLong
public void writeLong(long value) throws JMSExceptionAPI method. Writes a long to the stream message.- Specified by:
writeLongin interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeShort
public void writeShort(short value) throws JMSExceptionAPI method. Writes a short to the stream message.- Specified by:
writeShortin interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeString
public void writeString(String value) throws JMSException
API method. Writes a String to the stream message.- Specified by:
writeStringin interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.JMSException- If the value could not be written on the stream.
-
writeObject
public void writeObject(Object value) throws 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 interfaceStreamMessage- Parameters:
value- the value to be written.- Throws:
MessageNotWriteableException- If the message body is read-only.MessageFormatException- If the value type is invalid.JMSException- If the value could not be written on the stream.
-
readBoolean
public boolean readBoolean() throws JMSExceptionAPI method. Reads a boolean from the StreamMessage.- Specified by:
readBooleanin interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readByte
public byte readByte() throws JMSExceptionAPI method. Reads a byte from the StreamMessage.- Specified by:
readBytein interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readShort
public short readShort() throws JMSExceptionAPI method. Reads a short from the StreamMessage.- Specified by:
readShortin interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readChar
public char readChar() throws JMSExceptionAPI method. Reads a char from the StreamMessage.- Specified by:
readCharin interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readInt
public int readInt() throws JMSExceptionAPI method. Reads an int from the StreamMessage.- Specified by:
readIntin interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readLong
public long readLong() throws JMSExceptionAPI method. Reads a long from the StreamMessage.- Specified by:
readLongin interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readFloat
public float readFloat() throws JMSExceptionAPI method. Reads a float from the StreamMessage.- Specified by:
readFloatin interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readDouble
public double readDouble() throws JMSExceptionAPI method. Reads a double from the StreamMessage.- Specified by:
readDoublein interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readBytes
public int readBytes(byte[] bytes) throws 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 interfaceStreamMessage- 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:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readString
public String readString() throws JMSException
API method. Reads a String from the StreamMessage.- Specified by:
readStringin interfaceStreamMessage- Returns:
- a Unicode string from the SreamMessage.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the expected type is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
readObject
public Object readObject() throws JMSException
API method. Reads an objectified primitive type from the StreamMessage.- Specified by:
readObjectin interfaceStreamMessage- Returns:
- the value read.
- Throws:
MessageNotReadableException- If the message body is write-only.MessageFormatException- If reading the body is not possible.MessageEOFException- Unexpected end of bytes array.JMSException- internal error
-
reset
public void reset() throws JMSExceptionAPI method. Puts the message body in read-only mode and reset the stream to the beginning.- Specified by:
resetin interfaceStreamMessage- Throws:
JMSException- If an error occurs while closing the output stream.
-
prepare
protected void prepare() throws JMSExceptionMethod actually preparing the message for sending by transferring the local body into the wrapped MOM message.- Overrides:
preparein classMessage- Throws:
MessageFormatException- If an error occurs while serializing.JMSException
-
-