Class StreamMessage

    • Constructor Detail

      • StreamMessage

        StreamMessage()
               throws JMSException
        Instantiates a bright new StreamMessage.
        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 a StreamMessage wrapping 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: Message
        Returns 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:
        getBody in interface Message
        Overrides:
        getBody in class Message
        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 a TextMessage then this parameter must be set to String.class or another type to which a String is assignable.
        If the message is a ObjectMessage then parameter must be set to java.io.Serializable.class or another type to which the body is assignable.
        If the message is a MapMessage then this parameter must be set to java.util.Map.class (or java.lang.Object.class).
        If the message is a 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.
        If the message is a 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.
        If the message is a Message (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: Message
        API 2.0 method
        Specified by:
        isBodyAssignableTo in interface Message
        Overrides:
        isBodyAssignableTo in class Message
        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:
        getEffectiveBody in class Message
        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 JMSException
        API 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:
        clearBody in interface Message
        Overrides:
        clearBody in class Message
        Throws:
        JMSException - In case of an error while closing the input or output streams.
      • prepareWrite

        private void prepareWrite()
                           throws JMSException
        Internal 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 JMSException
        API 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:
        writeBoolean in interface StreamMessage
        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 JMSException
        API 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:
        writeBytes in interface StreamMessage
        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 JMSException
        API 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:
        writeBytes in interface StreamMessage
        Parameters:
        value - the byte array to be written.
        offset - the initial offset within the byte array
        length - 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.
      • 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:
        writeObject in interface StreamMessage
        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.
      • readBytes

        public int readBytes​(byte[] bytes)
                      throws JMSException
        API 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:
        readBytes in interface 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:
        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
      • reset

        public void reset()
                   throws JMSException
        API method. Puts the message body in read-only mode and reset the stream to the beginning.
        Specified by:
        reset in interface StreamMessage
        Throws:
        JMSException - If an error occurs while closing the output stream.