Class SQSBytesMessage
- All Implemented Interfaces:
jakarta.jms.BytesMessage
,jakarta.jms.Message
ActiveMQStreamMessage
, which is also
licensed under Apache2.0. Its methods are based largely on those found in
java.io.DataInputStream
and
java.io.DataOutputStream
.-
Nested Class Summary
Nested classes/interfaces inherited from class com.amazon.sqs.javamessaging.message.SQSMessage
SQSMessage.JMSMessagePropertyValue, SQSMessage.TypeConversionSupport
-
Field Summary
Fields inherited from class com.amazon.sqs.javamessaging.message.SQSMessage
BYTE_MESSAGE_TYPE, JMS_SQS_CORRELATION_ID, JMS_SQS_MESSAGE_TYPE, JMS_SQS_REPLY_TO_QUEUE_NAME, JMS_SQS_REPLY_TO_QUEUE_URL, OBJECT_MESSAGE_TYPE, TEXT_MESSAGE_TYPE
Fields inherited from interface jakarta.jms.Message
DEFAULT_DELIVERY_DELAY, DEFAULT_DELIVERY_MODE, DEFAULT_PRIORITY, DEFAULT_TIME_TO_LIVE
-
Constructor Summary
ConstructorsConstructorDescriptionCreate new empty BytesMessage to send.SQSBytesMessage
(Acknowledger acknowledger, String queueUrl, software.amazon.awssdk.services.sqs.model.Message sqsMessage) Convert received SQSMessage into BytesMessage. -
Method Summary
Modifier and TypeMethodDescriptionvoid
When the message is first created, and when clearBody is called, the body of the message is in write-only mode.byte[]
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.long
Gets the number of bytes of the message body when the message is in read-only mode.boolean
Reads aboolean
from the bytes message stream.byte
readByte()
Reads a signed 8-bit value from the bytes message stream.int
readBytes
(byte[] value) Reads a byte array from the bytes message stream.int
readBytes
(byte[] value, int length) Reads a portion of the bytes message stream.char
readChar()
Reads a Unicode character value from the bytes message stream.double
Reads adouble
from the bytes message stream.float
Reads afloat
from the bytes message stream.int
readInt()
Reads a 32-bit integer from the bytes message stream.long
readLong()
Reads a 64-bit integer from the bytes message stream.short
Reads a signed 16-bit number from the bytes message stream.int
Reads an unsigned 8-bit value from the bytes message stream.int
Reads an unsigned 16-bit number from the bytes message stream.readUTF()
Reads a string that has been encoded using a UTF-8 format from the bytes message streamvoid
reset()
Puts the message body in read-only mode and repositions the stream of bytes to the beginning.void
writeBoolean
(boolean value) Writes aboolean
to the bytes message streamvoid
writeByte
(byte value) Writes abyte
to the bytes message streamvoid
writeBytes
(byte[] value) Writes a byte array to the bytes message streamvoid
writeBytes
(byte[] value, int offset, int length) Writes a portion of a byte array to the bytes message stream.void
writeChar
(char value) Writes achar
to the bytes message streamvoid
writeDouble
(double value) Writes adouble
to the bytes message streamvoid
writeFloat
(float value) Writes afloat
to the bytes message streamvoid
writeInt
(int value) Writes aint
to the bytes message streamvoid
writeLong
(long value) Writes along
to the bytes message streamvoid
writeObject
(Object value) Writes an object to the bytes message stream.void
writeShort
(short value) Writes ashort
to the bytes message streamvoid
Writes a string that has been encoded using a UTF-8 format to the bytes message streamMethods inherited from class com.amazon.sqs.javamessaging.message.SQSMessage
acknowledge, checkBodyWritePermissions, checkPropertyWritePermissions, clearProperties, convertExceptionToJMSException, convertExceptionToMessageFormatException, getBody, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDeliveryTime, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSMessagePropertyValue, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getQueueUrl, getReceiptHandle, getShortProperty, getSQSMessageDeduplicationId, getSQSMessageGroupId, getSQSMessageId, getSQSMessageSequenceNumber, getStringProperty, isBodyAssignableTo, propertyExists, setBodyWritePermissions, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDeliveryTime, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setSequenceNumber, setShortProperty, setSQSMessageId, setStringProperty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jakarta.jms.Message
acknowledge, clearProperties, getBody, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDeliveryTime, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, isBodyAssignableTo, propertyExists, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDeliveryTime, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty
-
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.JMSExceptionCreate new empty BytesMessage to send.- Throws:
jakarta.jms.JMSException
-
-
Method Details
-
getBodyLength
public long getBodyLength() throws jakarta.jms.JMSExceptionGets 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 interfacejakarta.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.JMSExceptionReads aboolean
from the bytes message stream.- Specified by:
readBoolean
in interfacejakarta.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.JMSExceptionReads a signed 8-bit value from the bytes message stream.- Specified by:
readByte
in interfacejakarta.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.JMSExceptionReads an unsigned 8-bit value from the bytes message stream.- Specified by:
readUnsignedByte
in interfacejakarta.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.JMSExceptionReads a signed 16-bit number from the bytes message stream.- Specified by:
readShort
in interfacejakarta.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.JMSExceptionReads an unsigned 16-bit number from the bytes message stream.- Specified by:
readUnsignedShort
in interfacejakarta.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.JMSExceptionReads a Unicode character value from the bytes message stream.- Specified by:
readChar
in interfacejakarta.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.JMSExceptionReads a 32-bit integer from the bytes message stream.- Specified by:
readInt
in interfacejakarta.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.JMSExceptionReads a 64-bit integer from the bytes message stream.- Specified by:
readLong
in interfacejakarta.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.JMSExceptionReads afloat
from the bytes message stream.- Specified by:
readFloat
in interfacejakarta.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.JMSExceptionReads adouble
from the bytes message stream.- Specified by:
readDouble
in interfacejakarta.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
Reads a string that has been encoded using a UTF-8 format from the bytes message stream- Specified by:
readUTF
in interfacejakarta.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 interfacejakarta.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 interfacejakarta.jms.BytesMessage
- Parameters:
value
- The buffer into which the data is readlength
- 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 aboolean
to the bytes message stream- Specified by:
writeBoolean
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- Theboolean
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 abyte
to the bytes message stream- Specified by:
writeByte
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- Thebyte
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 ashort
to the bytes message stream- Specified by:
writeShort
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- Theshort
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 achar
to the bytes message stream- Specified by:
writeChar
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- Thechar
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 aint
to the bytes message stream- Specified by:
writeInt
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- Theint
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 along
to the bytes message stream- Specified by:
writeLong
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- Thelong
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 afloat
to the bytes message stream- Specified by:
writeFloat
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- Thefloat
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 adouble
to the bytes message stream- Specified by:
writeDouble
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- Thedouble
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
Writes a string that has been encoded using a UTF-8 format to the bytes message stream- Specified by:
writeUTF
in interfacejakarta.jms.BytesMessage
- Parameters:
value
- TheString
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 interfacejakarta.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 interfacejakarta.jms.BytesMessage
- Parameters:
value
- The portion of byte array value to be writtenoffset
- The initial offset within the byte arraylength
- 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
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 interfacejakarta.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.JMSExceptionPuts the message body in read-only mode and repositions the stream of bytes to the beginning.- Specified by:
reset
in interfacejakarta.jms.BytesMessage
- Throws:
jakarta.jms.JMSException
-
clearBody
public void clearBody() throws jakarta.jms.JMSExceptionWhen 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 interfacejakarta.jms.Message
- Overrides:
clearBody
in classSQSMessage
- Throws:
jakarta.jms.JMSException
- If directly called
-
getBodyAsBytes
public byte[] getBodyAsBytes() throws jakarta.jms.JMSExceptionReads 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
-