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_TYPEFields 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 TypeMethodDescriptionvoidWhen 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.longGets the number of bytes of the message body when the message is in read-only mode.booleanReads abooleanfrom the bytes message stream.bytereadByte()Reads a signed 8-bit value from the bytes message stream.intreadBytes(byte[] value) Reads a byte array from the bytes message stream.intreadBytes(byte[] value, int length) Reads a portion of the bytes message stream.charreadChar()Reads a Unicode character value from the bytes message stream.doubleReads adoublefrom the bytes message stream.floatReads afloatfrom the bytes message stream.intreadInt()Reads a 32-bit integer from the bytes message stream.longreadLong()Reads a 64-bit integer from the bytes message stream.shortReads a signed 16-bit number from the bytes message stream.intReads an unsigned 8-bit value from the bytes message stream.intReads 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 streamvoidreset()Puts the message body in read-only mode and repositions the stream of bytes to the beginning.voidwriteBoolean(boolean value) Writes abooleanto the bytes message streamvoidwriteByte(byte value) Writes abyteto the bytes message streamvoidwriteBytes(byte[] value) Writes a byte array to the bytes message streamvoidwriteBytes(byte[] value, int offset, int length) Writes a portion of a byte array to the bytes message stream.voidwriteChar(char value) Writes acharto the bytes message streamvoidwriteDouble(double value) Writes adoubleto the bytes message streamvoidwriteFloat(float value) Writes afloatto the bytes message streamvoidwriteInt(int value) Writes aintto the bytes message streamvoidwriteLong(long value) Writes alongto the bytes message streamvoidwriteObject(Object value) Writes an object to the bytes message stream.voidwriteShort(short value) Writes ashortto the bytes message streamvoidWrites 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, setStringPropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
getBodyLengthin 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 abooleanfrom the bytes message stream.- Specified by:
readBooleanin interfacejakarta.jms.BytesMessage- Returns:
- the
booleanvalue - 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:
readBytein 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:
readUnsignedBytein 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:
readShortin 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:
readUnsignedShortin 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:
readCharin 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:
readIntin 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:
readLongin 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 afloatfrom the bytes message stream.- Specified by:
readFloatin interfacejakarta.jms.BytesMessage- Returns:
- a
floatvalue 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 adoublefrom the bytes message stream.- Specified by:
readDoublein interfacejakarta.jms.BytesMessage- Returns:
- a
doublevalue 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:
readUTFin 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:
readBytesin 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
IndexOutOfBoundsExceptionis thrown. No bytes will be read from the stream for this exception case.- Specified by:
readBytesin 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 abooleanto the bytes message stream- Specified by:
writeBooleanin interfacejakarta.jms.BytesMessage- Parameters:
value- Thebooleanvalue 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 abyteto the bytes message stream- Specified by:
writeBytein interfacejakarta.jms.BytesMessage- Parameters:
value- Thebytevalue 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 ashortto the bytes message stream- Specified by:
writeShortin interfacejakarta.jms.BytesMessage- Parameters:
value- Theshortvalue 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 acharto the bytes message stream- Specified by:
writeCharin interfacejakarta.jms.BytesMessage- Parameters:
value- Thecharvalue 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 aintto the bytes message stream- Specified by:
writeIntin interfacejakarta.jms.BytesMessage- Parameters:
value- Theintvalue 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 alongto the bytes message stream- Specified by:
writeLongin interfacejakarta.jms.BytesMessage- Parameters:
value- Thelongvalue 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 afloatto the bytes message stream- Specified by:
writeFloatin interfacejakarta.jms.BytesMessage- Parameters:
value- Thefloatvalue 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 adoubleto the bytes message stream- Specified by:
writeDoublein interfacejakarta.jms.BytesMessage- Parameters:
value- Thedoublevalue 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:
writeUTFin interfacejakarta.jms.BytesMessage- Parameters:
value- TheStringvalue 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:
writeBytesin 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:
writeBytesin 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:
writeObjectin 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:
resetin 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:
clearBodyin interfacejakarta.jms.Message- Overrides:
clearBodyin 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
-