Class SQSBytesMessage
- java.lang.Object
-
- com.amazon.sqs.javamessaging.message.SQSMessage
-
- com.amazon.sqs.javamessaging.message.SQSBytesMessage
-
- All Implemented Interfaces:
javax.jms.BytesMessage
,javax.jms.Message
public class SQSBytesMessage extends SQSMessage implements javax.jms.BytesMessage
This class borrows fromActiveMQStreamMessage
, which is also licensed under Apache2.0. Its methods are based largely on those found injava.io.DataInputStream
andjava.io.DataOutputStream
.- See Also:
org.apache.activemq.command.ActiveMQStreamMessage
-
-
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
-
-
Constructor Summary
Constructors Constructor Description SQSBytesMessage()
Create 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearBody()
When the message is first created, and when clearBody is called, the body of the message is in write-only mode.byte[]
getBodyAsBytes()
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
getBodyLength()
Gets the number of bytes of the message body when the message is in read-only mode.boolean
readBoolean()
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
readDouble()
Reads adouble
from the bytes message stream.float
readFloat()
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
readShort()
Reads a signed 16-bit number from the bytes message stream.int
readUnsignedByte()
Reads an unsigned 8-bit value from the bytes message stream.int
readUnsignedShort()
Reads an unsigned 16-bit number from the bytes message stream.String
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
writeUTF(String value)
Writes a string that has been encoded using a UTF-8 format to the bytes message stream-
Methods inherited from class com.amazon.sqs.javamessaging.message.SQSMessage
acknowledge, checkBodyWritePermissions, checkPropertyWritePermissions, clearProperties, convertExceptionToJMSException, convertExceptionToMessageFormatException, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSMessagePropertyValue, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getQueueUrl, getReceiptHandle, getShortProperty, getSQSMessageDeduplicationId, getSQSMessageGroupId, getSQSMessageId, getSQSMessageSequenceNumber, getStringProperty, propertyExists, setBodyWritePermissions, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, 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 javax.jms.Message
acknowledge, clearProperties, getBooleanProperty, getByteProperty, getDoubleProperty, getFloatProperty, getIntProperty, getJMSCorrelationID, getJMSCorrelationIDAsBytes, getJMSDeliveryMode, getJMSDestination, getJMSExpiration, getJMSMessageID, getJMSPriority, getJMSRedelivered, getJMSReplyTo, getJMSTimestamp, getJMSType, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, propertyExists, setBooleanProperty, setByteProperty, setDoubleProperty, setFloatProperty, setIntProperty, setJMSCorrelationID, setJMSCorrelationIDAsBytes, setJMSDeliveryMode, setJMSDestination, setJMSExpiration, setJMSMessageID, setJMSPriority, setJMSRedelivered, setJMSReplyTo, setJMSTimestamp, setJMSType, setLongProperty, setObjectProperty, setShortProperty, setStringProperty
-
-
-
-
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 interfacejavax.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 aboolean
from the bytes message stream.- Specified by:
readBoolean
in interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 afloat
from the bytes message stream.- Specified by:
readFloat
in interfacejavax.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 adouble
from the bytes message stream.- Specified by:
readDouble
in interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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:
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 aboolean
to the bytes message stream- Specified by:
writeBoolean
in interfacejavax.jms.BytesMessage
- Parameters:
value
- Theboolean
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 abyte
to the bytes message stream- Specified by:
writeByte
in interfacejavax.jms.BytesMessage
- Parameters:
value
- Thebyte
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 ashort
to the bytes message stream- Specified by:
writeShort
in interfacejavax.jms.BytesMessage
- Parameters:
value
- Theshort
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 achar
to the bytes message stream- Specified by:
writeChar
in interfacejavax.jms.BytesMessage
- Parameters:
value
- Thechar
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 aint
to the bytes message stream- Specified by:
writeInt
in interfacejavax.jms.BytesMessage
- Parameters:
value
- Theint
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 along
to the bytes message stream- Specified by:
writeLong
in interfacejavax.jms.BytesMessage
- Parameters:
value
- Thelong
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 afloat
to the bytes message stream- Specified by:
writeFloat
in interfacejavax.jms.BytesMessage
- Parameters:
value
- Thefloat
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 adouble
to the bytes message stream- Specified by:
writeDouble
in interfacejavax.jms.BytesMessage
- Parameters:
value
- Thedouble
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 interfacejavax.jms.BytesMessage
- Parameters:
value
- TheString
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 interfacejavax.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 interfacejavax.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:
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 interfacejavax.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 interfacejavax.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 interfacejavax.jms.Message
- Overrides:
clearBody
in classSQSMessage
- 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
-
-