com.ibm.mq.headers
Class MQHeaderList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList
-
- com.ibm.mq.headers.MQHeaderList
-
- All Implemented Interfaces:
- java.lang.Iterable, java.util.Collection, java.util.List
public class MQHeaderList extends java.util.AbstractList
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
Constructors Constructor and Description MQHeaderList()
Default constructorMQHeaderList(java.io.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(java.io.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(java.io.DataInput message, java.lang.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(MQHeader[] headers)
Constructs an MQHeaderList from an array of headers.MQHeaderList(java.lang.String format)
Initializes an MQHeaderList for reading a byte stream starting with the specified initial format.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description void
add(int index, java.lang.Object header)
Inserts a new MQHeader instance before the given position in the list.boolean
add(java.lang.Object header)
Adds a new MQHeader instance to the end of the list.MQData
asMQData()
Returns an MQData adapter for this MQHeaderList.java.lang.Object
get(int index)
Returns the header object at the given position in the list.java.lang.Object
getBody()
Returns the body object obtained during the last read operation if the readBody argument was specified.java.lang.String
getFormat()
Returns the format for the first item in the header list.int
indexOf(java.lang.String type)
Returns the index of the first header in the list of the specified header type, or -1 if not found.int
read(java.io.DataInput message)
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.int
read(java.io.DataInput message, boolean readBody)
Populates an MQHeaderList from the contents of a message or byte stream and reads the message body if the readBody argument is true.int
read(java.io.DataInput message, int encoding, int characterSet)
Populates an MQHeaderList from the contents of a message or byte stream using the given initial format, encoding and CCSID.int
read(java.io.DataInput message, int encoding, int characterSet, boolean readBody)
Populates an MQHeaderList from the contents of a message or byte stream and reads the message body if the readBody argument is true.java.lang.Object
remove(int index)
Removes the MQHeader at the specified position in this list.java.lang.Object
set(int index, java.lang.Object header)
Replaces the MQHeader instance at the given position in the list with the specified value.void
setFormat(java.lang.String format)
int
size()
Returns the number of headers in the list.java.lang.String
toString()
Returns the string representation of the class instancejava.lang.String
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.java.lang.String
updateHeaderChaining(boolean useBodyFormat)
Deprecated.No longer requiredjava.lang.String
updateHeaderChaining(java.lang.String bodyFormat)
Updates the format of headers in the list, setting the last one to the given body format.int
write(java.io.DataOutput message)
Writes the headers in this MQHeaderList to the target message.int
write(java.io.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.int
write(java.io.DataOutput message, int encoding, int characterSet)
Writes the headers in this MQHeaderList to the target message using the given encoding and CCSID.int
write(java.io.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 java.util.AbstractList
addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
-
-
-
-
Constructor Detail
-
MQHeaderList
public MQHeaderList()
Default constructor
-
MQHeaderList
public MQHeaderList(java.lang.String format)
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
public MQHeaderList(MQHeader[] headers)
Constructs an MQHeaderList from an array of headers.- Parameters:
headers
- The array of headers
-
MQHeaderList
public MQHeaderList(java.io.DataInput message) throws MQDataException, java.io.IOException
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 failsjava.io.IOException
- If there is an IO error
-
MQHeaderList
public MQHeaderList(java.io.DataInput message, boolean readBody) throws MQDataException, java.io.IOException
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 failsjava.io.IOException
- If there is an IO error
-
MQHeaderList
public MQHeaderList(java.io.DataInput message, java.lang.String format, int encoding, int characterSet) throws MQDataException, java.io.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 failsjava.io.IOException
- If there is an IO error
-
-
Method Detail
-
updateHeaderChaining
public java.lang.String 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
public java.lang.String updateHeaderChaining(boolean useBodyFormat)
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()
-
updateHeaderChaining
public java.lang.String updateHeaderChaining(java.lang.String bodyFormat)
Updates the format of headers in the list, setting the last one to the given body format.- Parameters:
bodyFormat
- the header format (see CMQC.MQFMT_* for values)- Returns:
- The updated header chain
- See Also:
updateHeaderChaining()
-
read
public int read(java.io.DataInput message) throws MQDataException, java.io.IOException
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 failsjava.io.IOException
- If there is an IO error
-
read
public int read(java.io.DataInput message, boolean readBody) throws MQDataException, java.io.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.readBody
- a flag to indicate whether message body is to be read- Returns:
- The number of bytes read
- Throws:
MQDataException
- If the call failsjava.io.IOException
- If there is an IO error
-
read
public int read(java.io.DataInput message, int encoding, int characterSet) throws MQDataException, java.io.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 failsjava.io.IOException
- If there is an IO error
-
read
public int read(java.io.DataInput message, int encoding, int characterSet, boolean readBody) throws MQDataException, java.io.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 failsjava.io.IOException
- If there is an IO error
-
write
public int write(java.io.DataOutput message) throws java.io.IOException
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:
java.io.IOException
- If there is an IO error
-
write
public int write(java.io.DataOutput message, boolean writeBody) throws java.io.IOException
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:
java.io.IOException
- If there is an IO error
-
write
public int write(java.io.DataOutput message, int encoding, int characterSet) throws java.io.IOException
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:
java.io.IOException
- If there is an IO error
-
write
public int write(java.io.DataOutput message, int encoding, int characterSet, boolean writeBody) throws java.io.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:
java.io.IOException
- If there is an IO error
-
indexOf
public int indexOf(java.lang.String type)
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
public java.lang.String 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
public void setFormat(java.lang.String format)
- Parameters:
format
- the format for the first item in the header list
-
getBody
public java.lang.Object getBody()
Returns the body object obtained during the last read operation if the readBody argument was specified.- Returns:
- The body object
-
get
public java.lang.Object get(int index)
Returns the header object at the given position in the list.- Specified by:
get
in interfacejava.util.List
- Specified by:
get
in classjava.util.AbstractList
- 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:
size
in interfacejava.util.Collection
- Specified by:
size
in interfacejava.util.List
- Specified by:
size
in classjava.util.AbstractCollection
- Returns:
- The number of headers in the list
-
add
public void add(int index, java.lang.Object header)
Inserts a new MQHeader instance before the given position in the list.- Specified by:
add
in interfacejava.util.List
- Overrides:
add
in classjava.util.AbstractList
- Parameters:
index
- the position at which to insertheader
- the MQHeader to insert
-
add
public boolean add(java.lang.Object header)
Adds a new MQHeader instance to the end of the list.- Specified by:
add
in interfacejava.util.Collection
- Specified by:
add
in interfacejava.util.List
- Overrides:
add
in classjava.util.AbstractList
- Parameters:
header
- the MQHeader to add- Returns:
- true
-
remove
public java.lang.Object remove(int index)
Removes the MQHeader at the specified position in this list.- Specified by:
remove
in interfacejava.util.List
- Overrides:
remove
in classjava.util.AbstractList
- Parameters:
index
- the index of the element to removed.- Returns:
- the element previously at the specified position.
-
set
public java.lang.Object set(int index, java.lang.Object header)
Replaces the MQHeader instance at the given position in the list with the specified value.- Specified by:
set
in interfacejava.util.List
- Overrides:
set
in classjava.util.AbstractList
- Parameters:
index
- the position at which to replaceheader
- the MQHeader to replace with- Returns:
- The element previously at the specified position
-
asMQData
public MQData 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
public java.lang.String toString()
Returns the string representation of the class instance- Overrides:
toString
in classjava.util.AbstractCollection
- Returns:
- The string representation
- See Also:
Object.toString()
-
-