Class SQSBytesMessage

  • All Implemented Interfaces:
    javax.jms.BytesMessage, javax.jms.Message

    public class SQSBytesMessage
    extends SQSMessage
    implements javax.jms.BytesMessage
    This class borrows from ActiveMQStreamMessage, which is also licensed under Apache2.0. Its methods are based largely on those found in java.io.DataInputStream and java.io.DataOutputStream.
    See Also:
    org.apache.activemq.command.ActiveMQStreamMessage
    • Constructor Detail

      • SQSBytesMessage

        public SQSBytesMessage​(Acknowledger acknowledger,
                               String queueUrl,
                               software.amazon.awssdk.services.sqs.model.Message sqsMessage)
                        throws javax.jms.JMSException
        Convert received SQSMessage into BytesMessage.
        Throws:
        javax.jms.JMSException
      • SQSBytesMessage

        public SQSBytesMessage()
                        throws javax.jms.JMSException
        Create new empty BytesMessage to send.
        Throws:
        javax.jms.JMSException
    • Method Detail

      • getBodyLength

        public long getBodyLength()
                           throws javax.jms.JMSException
        Gets the number of bytes of the message body when the message is in read-only mode. The value returned can be used to allocate a byte array. The value returned is the entire length of the message body, regardless of where the pointer for reading the message is currently located.
        Specified by:
        getBodyLength in interface javax.jms.BytesMessage
        Returns:
        number of bytes in the message
        Throws:
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
        javax.jms.JMSException
      • readBoolean

        public boolean readBoolean()
                            throws javax.jms.JMSException
        Reads a boolean from the bytes message stream.
        Specified by:
        readBoolean in interface javax.jms.BytesMessage
        Returns:
        the boolean value
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readByte

        public byte readByte()
                      throws javax.jms.JMSException
        Reads a signed 8-bit value from the bytes message stream.
        Specified by:
        readByte in interface javax.jms.BytesMessage
        Returns:
        the next byte from the bytes message stream as a signed 8-bit byte
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readUnsignedByte

        public int readUnsignedByte()
                             throws javax.jms.JMSException
        Reads an unsigned 8-bit value from the bytes message stream.
        Specified by:
        readUnsignedByte in interface javax.jms.BytesMessage
        Returns:
        the next byte from the bytes message stream, interpreted as an unsigned 8-bit number
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readShort

        public short readShort()
                        throws javax.jms.JMSException
        Reads a signed 16-bit number from the bytes message stream.
        Specified by:
        readShort in interface javax.jms.BytesMessage
        Returns:
        the next two bytes from the bytes message stream, interpreted as a signed 16-bit number
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readUnsignedShort

        public int readUnsignedShort()
                              throws javax.jms.JMSException
        Reads an unsigned 16-bit number from the bytes message stream.
        Specified by:
        readUnsignedShort in interface javax.jms.BytesMessage
        Returns:
        the next two bytes from the bytes message stream, interpreted as an unsigned 16-bit integer
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readChar

        public char readChar()
                      throws javax.jms.JMSException
        Reads a Unicode character value from the bytes message stream.
        Specified by:
        readChar in interface javax.jms.BytesMessage
        Returns:
        a Unicode character from the bytes message stream
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readInt

        public int readInt()
                    throws javax.jms.JMSException
        Reads a 32-bit integer from the bytes message stream.
        Specified by:
        readInt in interface javax.jms.BytesMessage
        Returns:
        the next four bytes from the bytes message stream, interpreted as an int
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readLong

        public long readLong()
                      throws javax.jms.JMSException
        Reads a 64-bit integer from the bytes message stream.
        Specified by:
        readLong in interface javax.jms.BytesMessage
        Returns:
        a 64-bit integer value from the bytes message stream, interpreted as a long
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readFloat

        public float readFloat()
                        throws javax.jms.JMSException
        Reads a float from the bytes message stream.
        Specified by:
        readFloat in interface javax.jms.BytesMessage
        Returns:
        a float value from the bytes message stream
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readDouble

        public double readDouble()
                          throws javax.jms.JMSException
        Reads a double from the bytes message stream.
        Specified by:
        readDouble in interface javax.jms.BytesMessage
        Returns:
        a double value from the bytes message stream
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readUTF

        public String readUTF()
                       throws javax.jms.JMSException
        Reads a string that has been encoded using a UTF-8 format from the bytes message stream
        Specified by:
        readUTF in interface javax.jms.BytesMessage
        Returns:
        a Unicode string from the bytes message stream
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageEOFException - If unexpected end of bytes stream has been reached.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readBytes

        public int readBytes​(byte[] value)
                      throws javax.jms.JMSException
        Reads a byte array from the bytes message stream.

        If the length of array value is less than the number of bytes remaining to be read from the stream, the array should be filled. A subsequent call reads the next increment, and so on.

        If the number of bytes remaining in the stream is less than the length of array value, the bytes should be read into the array. The return value of the total number of bytes read will be less than the length of the array, indicating that there are no more bytes left to be read from the stream. The next read of the stream returns -1.

        Specified by:
        readBytes in interface javax.jms.BytesMessage
        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 stream has been reached
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • readBytes

        public int readBytes​(byte[] value,
                             int length)
                      throws javax.jms.JMSException
        Reads a portion of the bytes message stream.

        If the length of array value is less than the number of bytes remaining to be read from the stream, the array should be filled. A subsequent call reads the next increment, and so on.

        If the number of bytes remaining in the stream is less than the length of array value, the bytes should be read into the array. The return value of the total number of bytes read will be less than the length of the array, indicating that there are no more bytes left to be read from the stream. The next read of the stream returns -1.

        If length is negative, then an IndexOutOfBoundsException is thrown. No bytes will be read from the stream for this exception case.

        Specified by:
        readBytes in interface javax.jms.BytesMessage
        Parameters:
        value - The buffer into which the data is read
        length - The number of bytes to read; must be less than or equal to value.length
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached
        Throws:
        javax.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
        javax.jms.MessageNotReadableException - If the message is in write-only mode.
      • writeBoolean

        public void writeBoolean​(boolean value)
                          throws javax.jms.JMSException
        Writes a boolean to the bytes message stream
        Specified by:
        writeBoolean in interface javax.jms.BytesMessage
        Parameters:
        value - The boolean value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeByte

        public void writeByte​(byte value)
                       throws javax.jms.JMSException
        Writes a byte to the bytes message stream
        Specified by:
        writeByte in interface javax.jms.BytesMessage
        Parameters:
        value - The byte value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeShort

        public void writeShort​(short value)
                        throws javax.jms.JMSException
        Writes a short to the bytes message stream
        Specified by:
        writeShort in interface javax.jms.BytesMessage
        Parameters:
        value - The short value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeChar

        public void writeChar​(char value)
                       throws javax.jms.JMSException
        Writes a char to the bytes message stream
        Specified by:
        writeChar in interface javax.jms.BytesMessage
        Parameters:
        value - The char value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeInt

        public void writeInt​(int value)
                      throws javax.jms.JMSException
        Writes a int to the bytes message stream
        Specified by:
        writeInt in interface javax.jms.BytesMessage
        Parameters:
        value - The int value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeLong

        public void writeLong​(long value)
                       throws javax.jms.JMSException
        Writes a long to the bytes message stream
        Specified by:
        writeLong in interface javax.jms.BytesMessage
        Parameters:
        value - The long value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeFloat

        public void writeFloat​(float value)
                        throws javax.jms.JMSException
        Writes a float to the bytes message stream
        Specified by:
        writeFloat in interface javax.jms.BytesMessage
        Parameters:
        value - The float value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeDouble

        public void writeDouble​(double value)
                         throws javax.jms.JMSException
        Writes a double to the bytes message stream
        Specified by:
        writeDouble in interface javax.jms.BytesMessage
        Parameters:
        value - The double value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeUTF

        public void writeUTF​(String value)
                      throws javax.jms.JMSException
        Writes a string that has been encoded using a UTF-8 format to the bytes message stream
        Specified by:
        writeUTF in interface javax.jms.BytesMessage
        Parameters:
        value - The String value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeBytes

        public void writeBytes​(byte[] value)
                        throws javax.jms.JMSException
        Writes a byte array to the bytes message stream
        Specified by:
        writeBytes in interface javax.jms.BytesMessage
        Parameters:
        value - The byte array value to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeBytes

        public void writeBytes​(byte[] value,
                               int offset,
                               int length)
                        throws javax.jms.JMSException
        Writes a portion of a byte array to the bytes message stream.
        Specified by:
        writeBytes in interface javax.jms.BytesMessage
        Parameters:
        value - The portion of byte array value to be written
        offset - The initial offset within the byte array
        length - The number of bytes to use
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
      • writeObject

        public void writeObject​(Object value)
                         throws javax.jms.JMSException
        Writes an object to the bytes message stream.

        This method works only for the boxed primitive object types (Integer, Double, Long ...), String objects, and byte arrays.

        Specified by:
        writeObject in interface javax.jms.BytesMessage
        Parameters:
        value - The Java object to be written
        Throws:
        javax.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
        javax.jms.MessageNotWriteableException - If the message is in read-only mode.
        javax.jms.MessageFormatException - If the object is of an invalid type.
        NullPointerException - If the object is null.
      • reset

        public void reset()
                   throws javax.jms.JMSException
        Puts the message body in read-only mode and repositions the stream of bytes to the beginning.
        Specified by:
        reset in interface javax.jms.BytesMessage
        Throws:
        javax.jms.JMSException
      • clearBody

        public void clearBody()
                       throws javax.jms.JMSException
        When the message is first created, and when clearBody is called, the body of the message is in write-only mode. After the first call to reset is made, the message body goes to read-only mode. when the message is sent, the sender can retain and modify it without affecting the sent message. If clearBody is called on a message, when it is in read-only mode, the message body is cleared and the message goes to write-only mode.
        Specified by:
        clearBody in interface javax.jms.Message
        Overrides:
        clearBody in class SQSMessage
        Throws:
        javax.jms.JMSException - If directly called
      • getBodyAsBytes

        public byte[] getBodyAsBytes()
                              throws javax.jms.JMSException
        Reads the body of message, which can be either the body returned from the the receives message as bytes or the bytes put in bytesOut if it is a sent message.
        Returns:
        value The body returned as byte array
        Throws:
        javax.jms.JMSException