org.exolab.jmscts.jms.message
Class BasicStreamMessage

java.lang.Object
  |
  +--org.exolab.jmscts.jms.message.BasicMessage
        |
        +--org.exolab.jmscts.jms.message.BasicStreamMessage
All Implemented Interfaces:
javax.jms.Message, javax.jms.StreamMessage

public class BasicStreamMessage
extends BasicMessage
implements javax.jms.StreamMessage

This class provides a basic implementation of the javax.jms.ObjectMessage interface.

Version:
$Revision: 1.2 $ $Date: 2004/02/02 03:49:55 $
Author:
Tim Anderson
See Also:
StreamMessage

Fields inherited from interface javax.jms.Message
DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE
 
Constructor Summary
BasicStreamMessage()
          Construct a new BasicStreamMessage.
 
Method Summary
 void clearBody()
          Clear the message body
 boolean readBoolean()
          Read a boolean from the bytes message stream
 byte readByte()
          Read a byte value from the stream message
 int readBytes(byte[] value)
          Read a byte array field from the stream message into the specified byte[] object (the read buffer).
 char readChar()
          Read a Unicode character value from the stream message
 double readDouble()
          Read a double from the stream message
 float readFloat()
          Read a float from the stream message
 int readInt()
          Read a 32-bit integer from the stream message
 long readLong()
          Read a 64-bit integer from the stream message
 java.lang.Object readObject()
          Read a Java object from the stream message
 short readShort()
          Read a 16-bit number from the stream message.
 java.lang.String readString()
          Read in a string from the stream message
 void reset()
          Put the message body in read-only mode, and reposition the stream to the beginning
 void setReadOnly(boolean readOnly)
          Set the read-only mode of the message.
 void writeBoolean(boolean value)
          Write a boolean to the stream message.
 void writeByte(byte value)
          Write out a byte to the stream message
 void writeBytes(byte[] value)
          Write a byte array field to the stream message
 void writeBytes(byte[] value, int offset, int length)
          Write a portion of a byte array as a byte array field to the stream message
 void writeChar(char value)
          Write a char to the stream message
 void writeDouble(double value)
          Write a double to the stream message
 void writeFloat(float value)
          Write a float to the stream message
 void writeInt(int value)
          Write an int to the stream message
 void writeLong(long value)
          Write a long to the stream message
 void writeObject(java.lang.Object value)
          Write a Java object to the stream message
 void writeShort(short value)
          Write a short to the stream message
 void writeString(java.lang.String value)
          Write a string to the stream message
 
Methods inherited from class org.exolab.jmscts.jms.message.BasicMessage
acknowledge, checkPropertyWrite, checkRead, checkWrite, clearProperties, getBodyReadOnly, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertiesReadOnly, getPropertyNames, getShortProperty, getStringProperty, propertyExists, setBodyReadOnly, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setPropertiesReadOnly, setShortProperty, setStringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.jms.Message
acknowledge, clearProperties, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, propertyExists, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty
 

Constructor Detail

BasicStreamMessage

public BasicStreamMessage()
Construct a new BasicStreamMessage. When first created, the message is in write-only mode.
Method Detail

readBoolean

public boolean readBoolean()
                    throws javax.jms.JMSException
Read a boolean from the bytes message stream
Specified by:
readBoolean in interface javax.jms.StreamMessage
Returns:
the boolean value read
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid

readByte

public byte readByte()
              throws javax.jms.JMSException
Read a byte value from the stream message
Specified by:
readByte in interface javax.jms.StreamMessage
Returns:
the next byte from the stream message as an 8-bit byte
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid
java.lang.NumberFormatException - if numeric conversion is invalid

readShort

public short readShort()
                throws javax.jms.JMSException
Read a 16-bit number from the stream message.
Specified by:
readShort in interface javax.jms.StreamMessage
Returns:
a 16-bit number from the stream message
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid
java.lang.NumberFormatException - if numeric conversion is invalid

readChar

public char readChar()
              throws javax.jms.JMSException
Read a Unicode character value from the stream message
Specified by:
readChar in interface javax.jms.StreamMessage
Returns:
a Unicode character from the stream message
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid

readInt

public int readInt()
            throws javax.jms.JMSException
Read a 32-bit integer from the stream message
Specified by:
readInt in interface javax.jms.StreamMessage
Returns:
a 32-bit integer value from the stream message, interpreted as an int
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid
java.lang.NumberFormatException - if numeric conversion is invalid

readLong

public long readLong()
              throws javax.jms.JMSException
Read a 64-bit integer from the stream message
Specified by:
readLong in interface javax.jms.StreamMessage
Returns:
a 64-bit integer value from the stream message, interpreted as a long
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid
java.lang.NumberFormatException - if numeric conversion is invalid

readFloat

public float readFloat()
                throws javax.jms.JMSException
Read a float from the stream message
Specified by:
readFloat in interface javax.jms.StreamMessage
Returns:
a float value from the stream message
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid
NullPointerException - if the value is null
java.lang.NumberFormatException - if numeric conversion is invalid

readDouble

public double readDouble()
                  throws javax.jms.JMSException
Read a double from the stream message
Specified by:
readDouble in interface javax.jms.StreamMessage
Returns:
a double value from the stream message
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid
NullPointerException - if the value is null
java.lang.NumberFormatException - if numeric conversion is invalid

readString

public java.lang.String readString()
                            throws javax.jms.JMSException
Read in a string from the stream message
Specified by:
readString in interface javax.jms.StreamMessage
Returns:
a Unicode string from the stream message
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid

readBytes

public int readBytes(byte[] value)
              throws javax.jms.JMSException
Read a byte array field from the stream message into the specified byte[] object (the read 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 are 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 will return -1.

If the bytes array field value is null, readBytes returns -1.

If the bytes array field value is empty, readBytes returns 0.

Once the first readBytes call on a byte[] field value has been done, 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:
readBytes in interface javax.jms.StreamMessage
Parameters:
value - 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:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if an end of message stream
javax.jms.MessageFormatException - if this type conversion is invalid

readObject

public java.lang.Object readObject()
                            throws javax.jms.JMSException
Read a Java object from the stream message

Note that this method can be used to return in objectified format, an object that had been written to the stream with the equivalent writeObject method call, or it's equivalent primitive write method.

Note that byte values are returned as byte[], not Byte[].

Specified by:
readObject in interface javax.jms.StreamMessage
Returns:
a Java object from the stream message, in objectified format (eg. if it set as an int, then a Integer is returned).
Throws:
javax.jms.JMSException - if JMS fails to read message due to some internal JMS error
javax.jms.MessageEOFException - if end of message stream

writeBoolean

public void writeBoolean(boolean value)
                  throws javax.jms.MessageNotWriteableException
Write a boolean to the stream message. The value true is written out as the value (byte)1; the value false is written out as the value (byte)0.
Specified by:
writeBoolean in interface javax.jms.StreamMessage
Parameters:
value - the boolean value to be written.
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeByte

public void writeByte(byte value)
               throws javax.jms.MessageNotWriteableException
Write out a byte to the stream message
Specified by:
writeByte in interface javax.jms.StreamMessage
Parameters:
value - the byte value to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeShort

public void writeShort(short value)
                throws javax.jms.MessageNotWriteableException
Write a short to the stream message
Specified by:
writeShort in interface javax.jms.StreamMessage
Parameters:
value - the short to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeChar

public void writeChar(char value)
               throws javax.jms.MessageNotWriteableException
Write a char to the stream message
Specified by:
writeChar in interface javax.jms.StreamMessage
Parameters:
value - the char value to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeInt

public void writeInt(int value)
              throws javax.jms.MessageNotWriteableException
Write an int to the stream message
Specified by:
writeInt in interface javax.jms.StreamMessage
Parameters:
value - the int to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeLong

public void writeLong(long value)
               throws javax.jms.MessageNotWriteableException
Write a long to the stream message
Specified by:
writeLong in interface javax.jms.StreamMessage
Parameters:
value - the long to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeFloat

public void writeFloat(float value)
                throws javax.jms.MessageNotWriteableException
Write a float to the stream message
Specified by:
writeFloat in interface javax.jms.StreamMessage
Parameters:
value - the float value to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeDouble

public void writeDouble(double value)
                 throws javax.jms.MessageNotWriteableException
Write a double to the stream message
Specified by:
writeDouble in interface javax.jms.StreamMessage
Parameters:
value - the double value to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeString

public void writeString(java.lang.String value)
                 throws javax.jms.MessageNotWriteableException
Write a string to the stream message
Specified by:
writeString in interface javax.jms.StreamMessage
Parameters:
value - the String value to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeBytes

public void writeBytes(byte[] value)
                throws javax.jms.MessageNotWriteableException
Write a byte array field to the stream message

The byte array value is written as a byte array field into the StreamMessage. Consecutively written byte array fields are treated as two distinct fields when reading byte array fields.

Specified by:
writeBytes in interface javax.jms.StreamMessage
Parameters:
value - the byte array to be written
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeBytes

public void writeBytes(byte[] value,
                       int offset,
                       int length)
                throws javax.jms.MessageNotWriteableException
Write a portion of a byte array as a byte array field to the stream message

The a portion of the byte array value is written as a byte array field into the StreamMessage. Consecutively written byte array fields are treated as two distinct fields when reading byte array fields.

Specified by:
writeBytes in interface javax.jms.StreamMessage
Parameters:
value - the byte array value to be written
offset - the initial offset within the byte array
length - the number of bytes to write
Throws:
javax.jms.MessageNotWriteableException - if message in read-only mode

writeObject

public void writeObject(java.lang.Object value)
                 throws javax.jms.JMSException
Write a Java object to the stream message

Note that this method only works for the objectified primitive object types (Integer, Double, Long ...), String's and byte arrays.

Specified by:
writeObject in interface javax.jms.StreamMessage
Parameters:
value - the Java object to be written
Throws:
javax.jms.JMSException - if JMS fails to write message due to some internal JMS error
javax.jms.MessageFormatException - if the object is invalid
javax.jms.MessageNotWriteableException - if message in read-only mode

reset

public void reset()
Put the message body in read-only mode, and reposition the stream to the beginning
Specified by:
reset in interface javax.jms.StreamMessage

clearBody

public void clearBody()
               throws javax.jms.JMSException
Clear the message body
Specified by:
clearBody in interface javax.jms.Message
Overrides:
clearBody in class BasicMessage
Throws:
javax.jms.JMSException - if JMS fails to reset the message due to some internal JMS error.

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws javax.jms.JMSException
Set the read-only mode of the message.
Overrides:
setReadOnly in class BasicMessage
Parameters:
readOnly - if true, make the message body and properties read-only, and invoke reset()
Throws:
javax.jms.JMSException - if the read-only mode cannot be changed


Copyright © 2001-2004 JMS CTS Team. All Rights Reserved.