Class MQHeaderList
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
com.ibm.mq.headers.MQHeaderList
- All Implemented Interfaces:
Iterable, Collection, List, SequencedCollection
An MQHeaderList represents an ordered list of header instances. Like an MQHeaderIterator, an
MQHeaderList can read and decode header content from a message. The contents of the list can be
written out to another message, having first been modified if desired. Possible modifications
include removing headers, updating their field contents, and adding or inserting new headers.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructorMQHeaderList(MQHeader[] headers) Constructs an MQHeaderList from an array of headers.MQHeaderList(DataInput message) Initializes an MQHeaderList from the contents of a message or byte stream using the initial format, encoding and CCSID given by the MQMD fields in the message.MQHeaderList(DataInput message, boolean readBody) Initializes an MQHeaderList from the contents of a message or byte stream using the initial format, encoding and CCSID given by the MQMD fields in the message.MQHeaderList(DataInput message, String format, int encoding, int characterSet) Initializes an MQHeaderList from the contents of a message or byte stream using the given initial format, encoding and CCSID.MQHeaderList(String format) Initializes an MQHeaderList for reading a byte stream starting with the specified initial format. -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts a new MQHeader instance before the given position in the list.booleanAdds a new MQHeader instance to the end of the list.asMQData()Returns an MQData adapter for this MQHeaderList.get(int index) Returns the header object at the given position in the list.getBody()Returns the body object obtained during the last read operation if the readBody argument was specified.Returns the format for the first item in the header list.intReturns the index of the first header in the list of the specified header type, or -1 if not found.intPopulates an MQHeaderList from the contents of a message or byte stream using the initial format, encoding and CCSID given by the MQMD fields in the message.intPopulates an MQHeaderList from the contents of a message or byte stream and reads the message body if the readBody argument is true.intPopulates an MQHeaderList from the contents of a message or byte stream using the given initial format, encoding and CCSID.intPopulates an MQHeaderList from the contents of a message or byte stream and reads the message body if the readBody argument is true.remove(int index) Removes the MQHeader at the specified position in this list.Replaces the MQHeader instance at the given position in the list with the specified value.voidintsize()Returns the number of headers in the list.toString()Returns the string representation of the class instanceTraverses the headers in the list, updating the format field of each Chainable header and returning the format of the first header for setting into the message descriptor.updateHeaderChaining(boolean useBodyFormat) Deprecated.No longer requiredupdateHeaderChaining(String bodyFormat) Updates the format of headers in the list, setting the last one to the given body format.intwrite(DataOutput message) Writes the headers in this MQHeaderList to the target message.intwrite(DataOutput message, boolean writeBody) Writes the headers in this MQHeaderList to the target message, and writes the body if the writeBody argument is true and a body has previously been read.intwrite(DataOutput message, int encoding, int characterSet) Writes the headers in this MQHeaderList to the target message using the given encoding and CCSID.intwrite(DataOutput message, int encoding, int characterSet, boolean writeBody) Writes the headers in this MQHeaderList to the target message using the given encoding and CCSID, and writes the body if the writeBody argument is true and a body has previously been read.Methods inherited from class AbstractList
addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subListMethods inherited from class AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Constructor Details
-
MQHeaderList
public MQHeaderList()Default constructor -
MQHeaderList
Initializes an MQHeaderList for reading a byte stream starting with the specified initial format. This format is used in subsequent read operations to identify the first header.- Parameters:
format- The format to intialise
-
MQHeaderList
Constructs an MQHeaderList from an array of headers.- Parameters:
headers- The array of headers
-
MQHeaderList
Initializes an MQHeaderList from the contents of a message or byte stream using the initial format, encoding and CCSID given by the MQMD fields in the message. All headers visible from the current position in the message are consumed into the list and the message is left positioned at the start of the body data.- Parameters:
message- the message.- Throws:
MQDataException- If the call failsIOException- If there is an IO error
-
MQHeaderList
Initializes an MQHeaderList from the contents of a message or byte stream using the initial format, encoding and CCSID given by the MQMD fields in the message. All headers visible from the current position in the message are consumed into the list, and the body is read. The body object can be retrieved using the getBody method.- Parameters:
message- the message.readBody- a flag to indicate whether message body is to be read- Throws:
MQDataException- If the call failsIOException- If there is an IO error
-
MQHeaderList
public MQHeaderList(DataInput message, String format, int encoding, int characterSet) throws MQDataException, IOException Initializes an MQHeaderList from the contents of a message or byte stream using the given initial format, encoding and CCSID. All headers visible from the current position in the message are consumed into the list and the message is left positioned at the start of the body data.- 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.- Throws:
MQDataException- If the call failsIOException- If there is an IO error
-
-
Method Details
-
updateHeaderChaining
Traverses the headers in the list, updating the format field of each Chainable header and returning the format of the first header for setting into the message descriptor. The encoding and CCSID fields in the headers are not updated. If written to a message or byte stream using the write method, the header contents will be written in a uniform encoding and CCSID. The encoding and CCSID values come from the DataInput or the arguments to the write method, and the header content is converted to this encoding and CCSID during the write process. The effective encoding and CCSID settings are not disrupted or corrupted when headers are added, removed or re-ordered in the list.- Returns:
- The updated header chain
-
updateHeaderChaining
Deprecated.No longer requiredUpdates the format of headers in the list, setting the last one to the format of the existing body object, if any. A body object will only be present if the header list was constructed or read with the readBody option.- Parameters:
useBodyFormat- Indicates if bodyFormat has to be used- Returns:
- The updated body format
- See Also:
-
updateHeaderChaining
-
read
Populates an MQHeaderList from the contents of a message or byte stream using the initial format, encoding and CCSID given by the MQMD fields in the message. All headers visible from the current position in the message are consumed into the list and the message is left positioned at the start of the body data. The current contents of the list (if any) are discarded before the read begins.- Parameters:
message- the message.- Returns:
- The number of bytes read
- Throws:
MQDataException- If the call failsIOException- If there is an IO error
-
read
Populates an MQHeaderList from the contents of a message or byte stream and reads the message body if the readBody argument is true. The body object can be retrieved using the getBody method.- Parameters:
message- the message.readBody- a flag to indicate whether message body is to be read- Returns:
- The number of bytes read
- Throws:
MQDataException- If the call failsIOException- If there is an IO error
-
read
public int read(DataInput message, int encoding, int characterSet) throws MQDataException, IOException Populates an MQHeaderList from the contents of a message or byte stream using the given initial format, encoding and CCSID. All headers visible from the current position in the message are consumed into the list and the message is left positioned at the start of the body data. The current contents of the list (if any) are discarded before the read begins. The initial format used is the value originally passed in the constructor of this MQHeaderList, if applicable.- Parameters:
message- the message.encoding- the numeric encoding. see (CMQC.MQENC_* for values).characterSet- the Coded Character Set Identifier.- Returns:
- The number of bytes read
- Throws:
MQDataException- If the call failsIOException- If there is an IO error
-
read
public int read(DataInput message, int encoding, int characterSet, boolean readBody) throws MQDataException, IOException Populates an MQHeaderList from the contents of a message or byte stream and reads the message body if the readBody argument is true. The body object can be retrieved using the getBody method.- Parameters:
message- the message.encoding- the numeric encoding. see (CMQC.MQENC_* for values).characterSet- the Coded Character Set Identifier.readBody- Indicates if message body has to be read also- Returns:
- The number of bytes read
- Throws:
MQDataException- If the call failsIOException- If there is an IO error
-
write
Writes the headers in this MQHeaderList to the target message. The content is written using the encoding and characterSet values from the message descriptor.- Parameters:
message- the message.- Returns:
- The number of bytes written
- Throws:
IOException- If there is an IO error
-
write
Writes the headers in this MQHeaderList to the target message, and writes the body if the writeBody argument is true and a body has previously been read. The content is written using the encoding and characterSet values from the message descriptor.- Parameters:
message- the message.writeBody- whether or not the body should be written to the message- Returns:
- The number of bytes written
- Throws:
IOException- If there is an IO error
-
write
Writes the headers in this MQHeaderList to the target message using the given encoding and CCSID.- Parameters:
message- the message.encoding- the numeric encoding. see (CMQC.MQENC_* for values).characterSet- the Coded Character Set Identifier.- Returns:
- The number of bytes written
- Throws:
IOException- If there is an IO error
-
write
public int write(DataOutput message, int encoding, int characterSet, boolean writeBody) throws IOException Writes the headers in this MQHeaderList to the target message using the given encoding and CCSID, and writes the body if the writeBody argument is true and a body has previously been read.- Parameters:
message- the message.encoding- the numeric encoding. see (CMQC.MQENC_* for values).characterSet- the Coded Character Set Identifier.writeBody- whether or not the body should be written to the message- Returns:
- The number of bytes written
- Throws:
IOException- If there is an IO error
-
indexOf
Returns the index of the first header in the list of the specified header type, or -1 if not found.- Parameters:
type- identifies the header type required- Returns:
- Index of the first header of the specified type
-
getFormat
Returns the format for the first item in the header list. This value can be set into the MQMD or the preceding header if the contents of the header list are written into a message. The format value returned is the initial format passed as an argument to the MQHeaderIterator(java.lang.String) constructor (if applicable), or the value resulting from updateHeaderChaining having been invoked. The value may be null.- Returns:
- The format
-
setFormat
- Parameters:
format- the format for the first item in the header list
-
getBody
Returns the body object obtained during the last read operation if the readBody argument was specified.- Returns:
- The body object
-
get
Returns the header object at the given position in the list.- Specified by:
getin interfaceList- Specified by:
getin classAbstractList- Parameters:
index- the position required- Returns:
- The object at the specified position
-
size
public int size()Returns the number of headers in the list.- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceList- Specified by:
sizein classAbstractCollection- Returns:
- The number of headers in the list
-
add
Inserts a new MQHeader instance before the given position in the list.- Specified by:
addin interfaceList- Overrides:
addin classAbstractList- Parameters:
index- the position at which to insertheader- the MQHeader to insert
-
add
Adds a new MQHeader instance to the end of the list.- Specified by:
addin interfaceCollection- Specified by:
addin interfaceList- Overrides:
addin classAbstractList- Parameters:
header- the MQHeader to add- Returns:
- true
-
remove
Removes the MQHeader at the specified position in this list.- Specified by:
removein interfaceList- Overrides:
removein classAbstractList- Parameters:
index- the index of the element to removed.- Returns:
- the element previously at the specified position.
-
set
Replaces the MQHeader instance at the given position in the list with the specified value.- Specified by:
setin interfaceList- Overrides:
setin classAbstractList- Parameters:
index- the position at which to replaceheader- the MQHeader to replace with- Returns:
- The element previously at the specified position
-
asMQData
Returns an MQData adapter for this MQHeaderList. The MQHeaderList class does not directly implement the com.ibm.mq.headers.MQData interface because its size method conflicts with the size method from java.util.List. The size returned by the MQData adapter includes the size of the body object, if present. A body object will be present if the MQHeaderList was constructed or read with the readBody option.- Returns:
- The MQData adapter
-
toString
Returns the string representation of the class instance- Overrides:
toStringin classAbstractCollection- Returns:
- The string representation
- See Also:
-