Class MQHeaderList

All Implemented Interfaces:
Iterable, Collection, List, SequencedCollection

public class MQHeaderList extends 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
    Description
    Default constructor
    Constructs an MQHeaderList from an array of headers.
    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.
    Initializes an MQHeaderList for reading a byte stream starting with the specified initial format.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int index, Object header)
    Inserts a new MQHeader instance before the given position in the list.
    boolean
    add(Object header)
    Adds a new MQHeader instance to the end of the list.
    Returns an MQData adapter for this MQHeaderList.
    get(int index)
    Returns the header object at the given position in the list.
    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.
    int
    Returns the index of the first header in the list of the specified header type, or -1 if not found.
    int
    read(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(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(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(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.
    remove(int index)
    Removes the MQHeader at the specified position in this list.
    set(int index, Object header)
    Replaces the MQHeader instance at the given position in the list with the specified value.
    void
    setFormat(String format)
     
    int
    Returns the number of headers in the list.
    Returns the string representation of the class instance
    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.
    updateHeaderChaining(boolean useBodyFormat)
    Deprecated.
    No longer required
    Updates the format of headers in the list, setting the last one to the given body format.
    int
    write(DataOutput message)
    Writes the headers in this MQHeaderList to the target message.
    int
    write(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(DataOutput message, int encoding, int characterSet)
    Writes the headers in this MQHeaderList to the target message using the given encoding and CCSID.
    int
    write(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 Object

    getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface Collection

    parallelStream, removeIf, stream, toArray

    Methods inherited from interface Iterable

    forEach
  • Constructor Details

    • MQHeaderList

      public MQHeaderList()
      Default constructor
    • MQHeaderList

      public MQHeaderList(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(DataInput message) throws MQDataException, 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 fails
      IOException - If there is an IO error
    • MQHeaderList

      public MQHeaderList(DataInput message, boolean readBody) throws MQDataException, 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 fails
      IOException - 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 fails
      IOException - If there is an IO error
  • Method Details

    • updateHeaderChaining

      public 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 String updateHeaderChaining(boolean useBodyFormat)
      Deprecated.
      No longer required
      Updates 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

      public String updateHeaderChaining(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:
    • read

      public int read(DataInput message) throws MQDataException, 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 fails
      IOException - If there is an IO error
    • read

      public int read(DataInput message, 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.
      readBody - a flag to indicate whether message body is to be read
      Returns:
      The number of bytes read
      Throws:
      MQDataException - If the call fails
      IOException - 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 fails
      IOException - 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 fails
      IOException - If there is an IO error
    • write

      public int write(DataOutput message) throws 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:
      IOException - If there is an IO error
    • write

      public int write(DataOutput message, boolean writeBody) throws 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:
      IOException - If there is an IO error
    • write

      public int write(DataOutput message, int encoding, int characterSet) throws 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:
      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

      public int indexOf(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 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(String format)
      Parameters:
      format - the format for the first item in the header list
    • getBody

      public Object getBody()
      Returns the body object obtained during the last read operation if the readBody argument was specified.
      Returns:
      The body object
    • get

      public Object get(int index)
      Returns the header object at the given position in the list.
      Specified by:
      get in interface List
      Specified by:
      get in class 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 interface Collection
      Specified by:
      size in interface List
      Specified by:
      size in class AbstractCollection
      Returns:
      The number of headers in the list
    • add

      public void add(int index, Object header)
      Inserts a new MQHeader instance before the given position in the list.
      Specified by:
      add in interface List
      Overrides:
      add in class AbstractList
      Parameters:
      index - the position at which to insert
      header - the MQHeader to insert
    • add

      public boolean add(Object header)
      Adds a new MQHeader instance to the end of the list.
      Specified by:
      add in interface Collection
      Specified by:
      add in interface List
      Overrides:
      add in class AbstractList
      Parameters:
      header - the MQHeader to add
      Returns:
      true
    • remove

      public Object remove(int index)
      Removes the MQHeader at the specified position in this list.
      Specified by:
      remove in interface List
      Overrides:
      remove in class AbstractList
      Parameters:
      index - the index of the element to removed.
      Returns:
      the element previously at the specified position.
    • set

      public Object set(int index, Object header)
      Replaces the MQHeader instance at the given position in the list with the specified value.
      Specified by:
      set in interface List
      Overrides:
      set in class AbstractList
      Parameters:
      index - the position at which to replace
      header - 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 String toString()
      Returns the string representation of the class instance
      Overrides:
      toString in class AbstractCollection
      Returns:
      The string representation
      See Also: