public class MQHeaderIterator
extends com.ibm.mq.jmqi.JmqiObject
implements java.util.Iterator
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.
MQHeaderList| 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.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
getBody()
Skips any remaining headers.
|
byte[] |
getBodyAsBytes()
Skips any remaining headers
|
java.lang.String |
getBodyAsText()
Skips any remaining headers
|
boolean |
hasNext()
Indicates whether there is another Header
|
java.lang.Object |
next()
get the next Header
|
MQHeader |
nextHeader()
Synonym for the next method, but typed to return MQHeader.
|
java.io.DataInput |
skipHeaders()
Skips all headers remaining from the current message position.
|
public MQHeaderIterator(java.io.DataInput message)
message - the message.public MQHeaderIterator(java.io.DataInput message,
java.lang.String format,
int encoding,
int characterSet)
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.public boolean hasNext()
hasNext in interface java.util.Iteratorpublic java.lang.Object next()
next in interface java.util.Iteratorpublic MQHeader nextHeader()
public java.io.DataInput skipHeaders()
throws MQDataException,
java.io.IOException
MQDataExceptionjava.io.IOExceptionpublic java.lang.Object getBody()
throws MQDataException,
java.io.IOException
MQDataExceptionjava.io.IOExceptionpublic byte[] getBodyAsBytes()
throws MQDataException,
java.io.IOException
MQDataExceptionjava.io.IOExceptionpublic java.lang.String getBodyAsText()
throws MQDataException,
java.io.IOException
MQDataExceptionjava.io.IOException