MQMessage

public class MQMessage
extends MQMD
implements DataInputDataOutput
java.lang.Object
   |
   +----com.ibm.mq.MQMD
           |
           +----com.ibm.mq.MQMessage
          

MQMessage represents both the message descriptor and the data for a WebSphere MQ message. It has a group of methods for reading data from a message and a group of methods for writing data into a message. The format of numbers and strings used by these read and write methods is controlled by the encoding and characterSet fields. The remaining fields contain control information which accompanies the application message data when a message travels between sending and receiving applications.

Constructors

MQMessage

public MQMessage();

The default constructor. This creates a message with default message descriptor information and an empty message buffer.

Methods

clearMessage

public void clearMessage() throws IOException;

Discards any data in the message buffer and sets the cursor position to zero.

Exceptions

getDataLength

public int getDataLength() throws IOException;

Gets the number of bytes of message data remaining to be read.

getDataOffset

public int getDataOffset() throws IOException;

Returns the current cursor position within the message data (the point at which read and write operations take effect).

Returns
Exceptions

getMessageLength

public int getMessageLength() throws IOException;

Gets the number of bytes of message data in this message.

Returns
Exceptions

getTotalMessageLength

public int getTotalMessageLength();

Gets the total number of bytes in the message as stored on the message queue on which this message was held. This method reports the total size of the message on the queue when an MQQueue.get() method fails with an error code which indicates that the message has been truncated.

readBoolean

public boolean readBoolean() throws IOException, EOFException;

Reads a boolean from the current position in the message buffer.

Returns
Exceptions

readByte

public byte readByte() throws IOException, EOFException;

Reads a byte from the current position in the message buffer.

Returns
Exceptions

readChar

public char readChar() throws IOException, EOFException;

Reads a character from the current position in the message buffer.

Returns
Exceptions

readDecimal2

public short readDecimal2() throws IOException;

Reads a 2-byte packed decimal number in the range -999 to 999.

Returns
Exceptions

readDecimal4

public int readDecimal4() throws IOException;

Reads a 4-byte packed decimal number in the range -9,999,999 to 9,999,999.

Returns
Exceptions

readDecimal8

public long readDecimal8() throws IOException;

Reads an 8-byte packed decimal number in the range -999,999,999,999,999 to 999,999,999,999,999.

Returns
Exceptions

readDouble

public double readDouble() throws IOException, EOFException;

Reads a double from the current position in the message buffer.

Returns
Exceptions

readFloat

public float readFloat() throws IOException, EOFException;

Reads a double from the current position in the message buffer.

Returns
Exceptions

readFully

public void readFully(byte[] b) throws IOException;

Fills a byte array with data from the message buffer.

Parameters
Exceptions

readFully

public void readFully(byte[] b, int off, int len) throws IOException;

Partly fills a byte array with data from the message buffer.

Parameters
Exceptions

readInt

public int readInt() throws IOException;

Reads an integer from the current position in the message buffer.

Returns
Exceptions

readInt2

public short readInt2() throws IOException;

Identical to readShort(). Provided for cross-language WebSphere MQ API compatibility.

Returns
Exceptions

readInt4

public int readInt4() throws IOException;

Synonym for readInt(), provided for cross-language WebSphere MQ API compatibility.

Exceptions

readInt8

public long readInt8() throws IOException;

Identical to readLong(). Provided for cross-language WebSphere MQ API compatibility.

Returns
Exceptions

readLine

public String readLine() throws IOException;

Reads a line of text from the message. Converts from the codeset identified in characterSet, and then reads in a line that has been terminated by \n, \r, \r\n, EOF or the end of a UTF string.

Returns
Exceptions

readLong

public long readLong() throws IOException;

Reads an integer from the current position in the message buffer.

Returns
Exceptions

readMQMDE

public void readMQMDE() throws MQException, IOException;

Reads an imbedded extended MQMD object. It uses extended MQMD information to update encoding, characterSet, format, groupId, messageSequenceNumber , offset, messageFlags and originalLength fields. Only call this method if format is MQC.MQFMT_MD_EXTENSION .

Exceptions

readObject

public Object readObject() throws ClassNotFoundException, 
            InvalidClassException, StreamCorruptedException, 
            OptionalDataException, IOException;

Reads an object carried in the message.

Returns
Exceptions

readShort

public short readShort() throws IOException;

Reads a short from the current position in the message buffer.

Returns
Exceptions

readString

public String readString(int length) throws IOException;

Reads a string in the codeset identified by characterSet and converts it into Unicode.

Parameters

readStringOfByteLength

public String readStringOfByteLength(int numberOfBytes) 
              throws IOException, EOFException;

Reads a specified number of bytes and uses them to construct a new string using the character set specified by characterSet. When the given bytes are not valid in the given charset, the behavior of this method is dependant on the implementation of the JRE.

Where the byte length of a string is known, read the entire String in a single invocation of this method. This will avoid problems where byte and char boundaries do not coincide.

Parameters
Returns
Exceptions

readStringOfCharLength

public String readStringOfCharLength(int numberOfChars) 
              throws IOException, EOFException;

Reads a string in the codeset identified by characterSet and converts it into Unicode.

Parameters
Returns
Exceptions

readUInt2

public int readUInt2() throws IOException;

Identical to readUnsignedShort(), provided for cross-language WebSphere MQ API compatibility.

Returns
Exceptions

readUnsignedByte

public int readUnsignedByte() throws IOException;

Reads an unsigned byte from the current position in the message buffer.

Returns
Exceptions

readUnsignedShort

public int readUnsignedShort() throws IOException;

Reads an unsigned short from the current position in the message buffer.

Returns
Exceptions

readUTF

public String readUTF() throws IOException;

Reads a UTF format String from the current position in the message buffer.

Returns
Exceptions

resizeBuffer

public void resizeBuffer(int size) throws IOException;

Indicates to the MQMessage class the size of buffer that might be required. If the message currently contains message data and the new size is less than the current size, the message data is truncated. If this message is subsequently used with MQQueue.get(), then this is the size of buffer allocated for the get request.

Exceptions

seek

public void seek(int offset) throws EOFException;

Moves the cursor to a new absolute position in the message buffer. Subsequent reads and writes will start from this position in the buffer.

Parameters
Exceptions

setDataOffset

public void setDataOffset(int offset) throws EOFException;

Moves the cursor to a new absolute position in the message buffer. This method is identical to seek(), and is provided for cross-language compatibility with the other WebSphere MQ APIs.

Parameters
Exceptions

skipBytes

public int skipBytes(int n) throws IOException, EOFException;

Moves the cursor forward in the message buffer.

Parameters
Returns
Exceptions

write

public void write(byte[] b) throws IOException;

Writes an array of bytes into the message buffer at the current position.

Parameters
Returns
Exceptions

write

public void write(byte[] b, int off, int len) throws IOException;

Writes a series of bytes into the message buffer at the current position.

Parameters
Exceptions

write

public void write(int b) throws IOException;

Writes a byte into the message buffer at the current position.

Parameters
Exceptions

writeBoolean

public void writeBoolean(boolean v) throws IOException;

Writes a boolean into the message buffer at the current position.

Parameters
Exceptions

writeByte

public void writeByte(int v) throws IOException;

Writes a byte into the message buffer at the current position.

Parameters
Exceptions

writeBytes

public void writeBytes(String s) throws IOException;

Writes a String as a sequence of bytes into the message buffer at the current position.

Parameters
Exceptions

writeChar

public void writeChar(int v) throws IOException;

Writes a Unicode character into the message buffer at the current position.

Parameters
Exceptions

writeChars

public void writeChars(String s) throws IOException;

Writes a String as a sequence of Unicode characters into the message buffer at the current position.

Parameters
Exceptions

writeDecimal2

public void writeDecimal2(short v) throws IOException;

Writes a 2-byte packed decimal format number into the message buffer at the current position. The behavior of this method is determined by encoding. A value of MQC.MQENC_DECIMAL_NORMAL writes a big-endian packed decimal and a value of MQC.MQENC_DECIMAL_REVERSED writes a little-endian packed decimal.

Parameters
Exceptions

writeDecimal4

public void writeDecimal4(int v) throws IOException;

Writes a 4-byte packed decimal format number into the message buffer at the current position. The behavior of this method is determined by encoding. A value of MQC.MQENC_DECIMAL_NORMAL writes a big-endian packed decimal and a value of MQC.MQENC_DECIMAL_REVERSED writes a little-endian packed decimal.

Parameters
Exceptions

writeDecimal8

public void writeDecimal8(long v) throws IOException;

Writes an 8-byte packed decimal format number into the message buffer at the current position. The behavior of this method is determined by encoding. A value of MQC.MQENC_DECIMAL_NORMAL writes a big-endian packed decimal and a value of MQC.MQENC_DECIMAL_REVERSED writes a little-endian packed decimal.

Parameters
Exceptions

writeDouble

public void writeDouble(double v) throws IOException;

Writes a double into the message buffer at the current position. The behavior of this method is determined by encoding.

Values of MQC.MQENC_FLOAT_IEEE_NORMAL and MQENC_IEEE_FLOAT_REVERSED write IEEE standard floats in big-endian and little-endian formats respectively.

A value of MQC.MQENC_FLOAT_S390 writes a zSeries format floating point number. Note that the range of IEEE doubles is greater than the range of zSeries double precision floating point numbers, and that very large numbers cannot be converted.

Parameters
Exceptions

writeFloat

public void writeFloat(float v) throws IOException;

Writes a float into the message buffer at the current position. The behavior of this method is determined by encoding.

Values of MQC.MQENC_FLOAT_IEEE_NORMAL and MQENC_IEEE_FLOAT_REVERSED write IEEE standard floats in big-endian and little-endian formats respectively.

A value of MQC.MQENC_FLOAT_S390 writes a zSeries format floating point number. Note that the range of IEEE doubles is greater than the range of zSeries double precision floating point numbers, and that very large numbers cannot be converted.

Parameters
Exceptions

writeInt

public void writeInt(int v) throws IOException;

Writes an int into the message buffer at the current position. The behavior of this method is determined by encoding.

Values of MQC.MQENC_INTEGER_NORMAL and MQC.MQENC_INTEGER_REVERSED write integers in big-endian and little-endian formats respectively.

Parameters
Exceptions

writeInt2

public void writeInt2(int v) throws IOException;

Identical to writeShort(), provided for cross-language WebSphere MQ API compatibility.

Parameters
Exceptions

writeInt4

public void writeInt4(int v) throws IOException;

Synonym for writeInt(), provided for cross-language WebSphere MQ API compatibility.

Exceptions

writeInt8

public void writeInt8(long v) throws IOException;

Synonym for writeLong(), provided for cross-language WebSphere MQ API compatibility.

Exceptions

writeLong

public void writeLong(long v) throws IOException;

Writes a long into the message buffer at the current position. The behavior of this method is determined by encoding.

Values of MQC.MQENC_INTEGER_NORMAL and MQC.MQENC_INTEGER_REVERSED write longs in big-endian and little-endian formats respectively.

Parameters
Exceptions

writeMQMDE

public void writeMQMDE() throws IOException, MQException;

Writes an extended MQMD object into the message at the current position. Values for the MQMDE are drawn from the field values: encoding, characterSet, format, groupId, messageSequenceNumber, offset, messageFlags and originalLength fields. The current value of the format field is written into the MDE, and the format field is then set to MQFMT_MD_EXTENSION.

Exceptions

writeObject

public void writeObject(Object obj) throws IOException;

Writes an Object into the message.

Parameters
Exceptions

writeShort

public void writeShort(int v) throws IOException;

Writes a short into the message buffer at the current position. The behavior of this method is determined by encoding.

Values of MQC.MQENC_INTEGER_NORMAL and MQC.MQENC_INTEGER_REVERSED write shorts in big-endian and little-endian formats respectively.

A value of MQC.MQENC_FLOAT_S390 writes a zSeries format floating point number.

Parameters
Exceptions

writeString

public void writeString(String s) throws IOException;

Writes a String into the message buffer at the current position, converting it to the codeset identified by characterSet.

Parameters
Exceptions

writeUTF

public void writeUTF(String str) throws IOException;

Writes a String in UTF format into the message buffer at the current position.

Parameters
Exceptions