Class SQSBytesMessage

java.lang.Object
com.amazon.sqs.javamessaging.message.SQSMessage
com.amazon.sqs.javamessaging.message.SQSBytesMessage
All Implemented Interfaces:
jakarta.jms.BytesMessage, jakarta.jms.Message

public class SQSBytesMessage extends SQSMessage implements jakarta.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.
  • Constructor Details

    • SQSBytesMessage

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

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

    • getBodyLength

      public long getBodyLength() throws jakarta.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 jakarta.jms.BytesMessage
      Returns:
      number of bytes in the message
      Throws:
      jakarta.jms.MessageNotReadableException - If the message is in write-only mode.
      jakarta.jms.JMSException
    • readBoolean

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

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

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

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

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

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

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

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

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

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

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

      public int readBytes(byte[] value) throws jakarta.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 jakarta.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:
      jakarta.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
      jakarta.jms.MessageNotReadableException - If the message is in write-only mode.
    • readBytes

      public int readBytes(byte[] value, int length) throws jakarta.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 jakarta.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:
      jakarta.jms.JMSException - If the JMS provider fails to read the message due to some internal error.
      jakarta.jms.MessageNotReadableException - If the message is in write-only mode.
    • writeBoolean

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

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

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

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

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

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

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

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

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

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

      public void writeBytes(byte[] value, int offset, int length) throws jakarta.jms.JMSException
      Writes a portion of a byte array to the bytes message stream.
      Specified by:
      writeBytes in interface jakarta.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:
      jakarta.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
      jakarta.jms.MessageNotWriteableException - If the message is in read-only mode.
    • writeObject

      public void writeObject(Object value) throws jakarta.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 jakarta.jms.BytesMessage
      Parameters:
      value - The Java object to be written
      Throws:
      jakarta.jms.JMSException - If the JMS provider fails to write the message due to some internal error.
      jakarta.jms.MessageNotWriteableException - If the message is in read-only mode.
      jakarta.jms.MessageFormatException - If the object is of an invalid type.
      NullPointerException - If the object is null.
    • reset

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

      public void clearBody() throws jakarta.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 jakarta.jms.Message
      Overrides:
      clearBody in class SQSMessage
      Throws:
      jakarta.jms.JMSException - If directly called
    • getBodyAsBytes

      public byte[] getBodyAsBytes() throws jakarta.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:
      jakarta.jms.JMSException