com.ibm.mq.headers
Class MQHeaderIterator
- java.lang.Object
-
- com.ibm.mq.jmqi.JmqiObject
-
- com.ibm.mq.headers.MQHeaderIterator
-
- All Implemented Interfaces:
- java.util.Iterator
public class MQHeaderIterator extends com.ibm.mq.jmqi.JmqiObject implements java.util.IteratorAn MQHeaderIterator returns headers one by one from a message. This class provides an easy way for an application to access header content in a message.Examples
Print out all the headers in a message
DataInput message = ... MQHeaderIterator it = new MQHeaderIterator (message); while (it.hasNext ()) { MQHeader header = it.nextHeader (); System.out.println ("Header (type " + header.type + "): " + header); }Skip over all headers in a message
DataInput message = ... MQHeaderIterator it = new MQHeaderIterator (message); it.skipHeaders ();
The message read cursor is now positioned immediately after the last header.
Extract the body of the message as a String, skipping any headers present
DataInput message = ...; String body = new MQHeaderIterator (message).getBodyAsText ();
The getBodyAsBytes method is similar but returns the message body as a byte array.
For the ability to search directly for particular headers, remove headers from a message, and other goodies, see MQHeaderList.
- See Also:
MQHeaderList
-
-
Constructor Summary
Constructors Constructor and Description MQHeaderIterator(java.io.DataInput message)Constructs an MQHeaderIterator around a message.MQHeaderIterator(java.io.DataInput message, java.lang.String format, int encoding, int characterSet)Constructs an MQHeaderIterator around a message or byte stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.ObjectgetBody()Skips any remaining headers.byte[]getBodyAsBytes()Skips any remaining headersjava.lang.StringgetBodyAsText()Skips any remaining headersbooleanhasNext()Indicates whether there is another Headerjava.lang.Objectnext()get the next HeaderMQHeadernextHeader()Synonym for the next method, but typed to return MQHeader.java.io.DataInputskipHeaders()Skips all headers remaining from the current message position.
-
-
-
Constructor Detail
-
MQHeaderIterator
public MQHeaderIterator(java.io.DataInput message)
Constructs an MQHeaderIterator around a message. Header content will be read from the current position of the message read cursor. The initial format, encoding and CCSID used to interpret the content are taken from the MQMD fields in the message.- Parameters:
message- the message.
-
MQHeaderIterator
public MQHeaderIterator(java.io.DataInput message, java.lang.String format, int encoding, int characterSet)Constructs an MQHeaderIterator around a message or byte stream. Header content will be read from the current position of the message read cursor or position in the byte stream. The initial format encoding and CCSID used to interpret the content are taken from the arguments.- Parameters:
message- the message.format- the message format (see CMQC.MQFMT_* for values)encoding- the numeric encoding. see (CMQC.MQENC_* for values)characterSet- the Coded Character Set Identifier.
-
-
Method Detail
-
hasNext
public boolean hasNext()
Indicates whether there is another Header- Specified by:
hasNextin interfacejava.util.Iterator- Returns:
- true or false as appropriate
-
next
public java.lang.Object next()
get the next Header- Specified by:
nextin interfacejava.util.Iterator- Returns:
- the next header
-
nextHeader
public MQHeader nextHeader()
Synonym for the next method, but typed to return MQHeader.- Returns:
- the next header
-
skipHeaders
public java.io.DataInput skipHeaders() throws MQDataException, java.io.IOExceptionSkips all headers remaining from the current message position.- Returns:
- the original message or byte stream positioned immediately following the last header.
- Throws:
MQDataExceptionjava.io.IOException
-
getBody
public java.lang.Object getBody() throws MQDataException, java.io.IOExceptionSkips any remaining headers.- Returns:
- the message body as either a String or a byte array according to the format of the last header. If the format is MQFMT_STRING, the body is a String; otherwise it is a byte array.
- Throws:
MQDataExceptionjava.io.IOException
-
getBodyAsBytes
public byte[] getBodyAsBytes() throws MQDataException, java.io.IOExceptionSkips any remaining headers- Returns:
- the message body as a byte array. This method returns a byte array even if the last format is MQFMT_STRING.
- Throws:
MQDataExceptionjava.io.IOException
-
getBodyAsText
public java.lang.String getBodyAsText() throws MQDataException, java.io.IOExceptionSkips any remaining headers- Returns:
- the message body as a String. This method returns a String regardless of the format field of the last header. The byte content of the message body is converted into a String using the CCSID indicated by the last header (or by the MQMD, if there are no headers, or no headers with chaining information).
- Throws:
MQDataExceptionjava.io.IOException
-
-