public class Metadata
extends java.lang.Object
The class is thread safe, as it uses a ConcurrentHashMap for the backend
Null value are transformed to empty string.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Metadata.ParseListener
Call backs during parsing process
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<java.lang.String,java.lang.String> |
dictionary |
static java.lang.String |
IDENTITY |
static java.lang.String |
PEER_ADDRESS |
static java.lang.String |
SOCKET_TYPE |
static java.lang.String |
USER_ID |
| Constructor and Description |
|---|
Metadata() |
Metadata(java.util.Map<java.lang.String,java.lang.String> dictionary) |
Metadata(java.util.Properties dictionary) |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
bytes()
Return the content of the metadata as a new byte array, using the specifications of the ZMTP protocol
|
private byte[] |
bytes(java.nio.ByteBuffer buf,
int position,
int length) |
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.
|
void |
clear()
Removes all the properties.
|
boolean |
containsKey(java.lang.String property)
Returns
true if this metada contains the property requested |
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> |
entrySet()
Returns a
Set view of the properties contained in this metadata. |
boolean |
equals(java.lang.Object other) |
java.lang.String |
get(java.lang.String property)
Returns the value for this property,
or
null if it does not exist. |
int |
hashCode() |
boolean |
isEmpty()
Returns
true if this map contains no key-value mappings. |
java.util.Set<java.lang.String> |
keySet()
Returns a
Set view of the keys contained in this metadata. |
void |
put(java.lang.String property,
java.lang.String value)
Define the value for this property.
|
int |
read(java.nio.ByteBuffer msg,
int offset,
Metadata.ParseListener listener)
Deserialize metadata from a
ByteBuffer, using the specifications of the ZMTP protocol |
int |
read(Msg msg,
int offset,
Metadata.ParseListener listener)
Deserialize metadata from a
Msg, using the specifications of the ZMTP protocol |
void |
remove(java.lang.String key)
Removes the property for a name from this metada if it is present.
|
void |
set(Metadata zapProperties) |
void |
set(java.lang.String property,
java.lang.String value)
Deprecated.
Use
put(String, String) instead |
int |
size()
Returns the number of properties.
|
java.lang.String |
toString() |
java.util.Collection<java.lang.String> |
values()
Returns a
Collection view of the values contained in this metadata. |
void |
write(java.io.OutputStream stream)
Serialize metadata to an output stream, using the specifications of the ZMTP protocol
|
public static final java.lang.String IDENTITY
public static final java.lang.String SOCKET_TYPE
public static final java.lang.String USER_ID
public static final java.lang.String PEER_ADDRESS
private final java.util.Map<java.lang.String,java.lang.String> dictionary
public Metadata()
public Metadata(java.util.Properties dictionary)
public Metadata(java.util.Map<java.lang.String,java.lang.String> dictionary)
public java.util.Set<java.lang.String> keySet()
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.public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
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.public java.util.Collection<java.lang.String> values()
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.public void remove(java.lang.String key)
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.
key - key whose mapping is to be removed from the mappublic java.lang.String get(java.lang.String property)
null if it does not exist.property - the property namenull if it does not exist.@Deprecated
public void set(java.lang.String property,
java.lang.String value)
put(String, String) insteadproperty - the property namevalue - value to be associated with the specified propertypublic void put(java.lang.String property,
java.lang.String value)
property - the property namevalue - value to be associated with the specified propertypublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic void set(Metadata zapProperties)
public boolean isEmpty()
true if this map contains no key-value mappings.true if this map contains no key-value mappingspublic boolean containsKey(java.lang.String property)
true if this metada contains the property requestedproperty - property the name of the property to be tested.true if this metada contains the propertypublic void clear()
public int size()
Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.public java.lang.String toString()
toString in class java.lang.Objectpublic byte[] bytes()
property = name value name = OCTET 1*255name-char name-char = ALPHA | DIGIT | "-" | "_" | "." | "+" value = 4OCTET *OCTET ; Size in network byte order
java.lang.IllegalStateException - if the content can't be serializedprivate int bytesSize()
public void write(java.io.OutputStream stream)
throws java.io.IOException
property = name value name = OCTET 1*255name-char name-char = ALPHA | DIGIT | "-" | "_" | "." | "+" value = 4OCTET *OCTET ; Size in network byte order
stream - java.io.IOException - if an I/O error occurs.java.lang.IllegalStateException - if one of the properties name size is bigger than 255public int read(Msg msg, int offset, Metadata.ParseListener listener)
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
msg - offset - listener - an optional Metadata.ParseListener, can be null.zmq.ZError.EPROTO or the error value from the Metadata.ParseListener.public int read(java.nio.ByteBuffer msg,
int offset,
Metadata.ParseListener listener)
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
msg - offset - listener - an optional Metadata.ParseListener, can be null.zmq.ZError.EPROTO or the error value from the Metadata.ParseListener.private byte[] bytes(java.nio.ByteBuffer buf,
int position,
int length)