Package zmq.io

Class Metadata

java.lang.Object
zmq.io.Metadata

public class Metadata extends Object
The metadata holder class.

The class is thread safe, as it uses a ConcurrentHashMap for the backend

Null value are transformed to empty string.

  • Field Details

  • Constructor Details

    • Metadata

      public Metadata()
    • Metadata

      public Metadata(Properties dictionary)
    • Metadata

      public Metadata(Map<String,String> dictionary)
  • Method Details

    • keySet

      public Set<String> keySet()
      Returns a Set view of the keys contained in this metadata. The set is backed by the metadata, so changes to the map are reflected in the set, and vice-versa. If the metadata is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the metadata, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
      Returns:
      a set view of the keys contained in this metadata
    • entrySet

      public Set<Map.Entry<String,String>> entrySet()
      Returns a Set view of the properties contained in this metadata. The set is backed by the metadata, so changes to the metadata are reflected in the set, and vice-versa. If the metadata is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a metadata property returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the metadata, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
      Returns:
      a set view of the properties contained in this metadata
    • values

      public Collection<String> values()
      Returns a Collection view of the values contained in this metadata. The collection is backed by the metadata, so changes to the map are reflected in the collection, and vice-versa. If the metadata is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding property from the metadata, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.
      Returns:
      a collection view of the values contained in this map
    • remove

      public void remove(String key)
      Removes the property for a name from this metada if it is present.

      If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

      The map will not contain a mapping for the specified key once the call returns.

      Parameters:
      key - key whose mapping is to be removed from the map
    • get

      public String get(String property)
      Returns the value for this property, or null if it does not exist.
      Parameters:
      property - the property name
      Returns:
      the value of the property, or null if it does not exist.
    • set

      @Deprecated public void set(String property, String value)
      Deprecated.
      Define the value for this property. If the value is null, an empty string is stored instead.
      Parameters:
      property - the property name
      value - value to be associated with the specified property
    • put

      public void put(String property, String value)
      Define the value for this property. If the value is null, an empty string is stored instead.
      Parameters:
      property - the property name
      value - value to be associated with the specified property
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • set

      public void set(Metadata zapProperties)
    • isEmpty

      public boolean isEmpty()
      Returns true if this map contains no key-value mappings.
      Returns:
      true if this map contains no key-value mappings
    • containsKey

      public boolean containsKey(String property)
      Returns true if this metada contains the property requested
      Parameters:
      property - property the name of the property to be tested.
      Returns:
      true if this metada contains the property
    • clear

      public void clear()
      Removes all the properties. The map will be empty after this call returns.
    • size

      public int size()
      Returns the number of properties. If it contains more properties than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
      Returns:
      the number of properties
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • bytes

      public byte[] bytes()
      Return the content of the metadata as a new byte array, using the specifications of the ZMTP protocol
       property = name value
       name = OCTET 1*255name-char
       name-char = ALPHA | DIGIT | "-" | "_" | "." | "+"
       value = 4OCTET *OCTET       ; Size in network byte order
       
      Returns:
      a new byte array
      Throws:
      IllegalStateException - if the content can't be serialized
    • bytesSize

      private int bytesSize()
      Return an approximate size of the serialization of the metadata, it will probably be higher if there is a lot of non ASCII value in it.
      Returns:
      the size estimation
    • write

      public void write(OutputStream stream) throws IOException
      Serialize metadata to an output stream, using the specifications of the ZMTP protocol
       property = name value
       name = OCTET 1*255name-char
       name-char = ALPHA | DIGIT | "-" | "_" | "." | "+"
       value = 4OCTET *OCTET       ; Size in network byte order
       
      Parameters:
      stream -
      Throws:
      IOException - if an I/O error occurs.
      IllegalStateException - if one of the properties name size is bigger than 255
    • read

      public int read(Msg msg, int offset, Metadata.ParseListener listener)
      Deserialize metadata from a Msg, using the specifications of the ZMTP protocol
       property = name value
       name = OCTET 1*255name-char
       name-char = ALPHA | DIGIT | "-" | "_" | "." | "+"
       value = 4OCTET *OCTET       ; Size in network byte order
       
      Parameters:
      msg -
      offset -
      listener - an optional Metadata.ParseListener, can be null.
      Returns:
      0 if successful. Otherwise, it returns zmq.ZError.EPROTO or the error value from the Metadata.ParseListener.
    • read

      public int read(ByteBuffer msg, int offset, Metadata.ParseListener listener)
      Deserialize metadata from a ByteBuffer, using the specifications of the ZMTP protocol
       property = name value
       name = OCTET 1*255name-char
       name-char = ALPHA | DIGIT | "-" | "_" | "." | "+"
       value = 4OCTET *OCTET       ; Size in network byte order
       
      Parameters:
      msg -
      offset -
      listener - an optional Metadata.ParseListener, can be null.
      Returns:
      0 if successful. Otherwise, it returns zmq.ZError.EPROTO or the error value from the Metadata.ParseListener.
    • bytes

      private byte[] bytes(ByteBuffer buf, int position, int length)