com.apple.dnssd
Class TXTRecord

java.lang.Object
  extended by com.apple.dnssd.TXTRecord

public class TXTRecord
extends java.lang.Object

Object used to construct and parse DNS-SD format TXT records. For more info see DNS-Based Service Discovery, section 6.


Constructor Summary
TXTRecord()
          Constructs a new, empty TXT record.
TXTRecord(byte[] initBytes)
          Constructs a new TXT record from a byte array in the standard format.
 
Method Summary
 boolean contains(java.lang.String key)
          Return true if key is present in the TXT record, false if not.
 java.lang.String getKey(int index)
          Return a key in the TXT record by zero-based index.
 byte[] getRawBytes()
          Return the contents of the TXT record as raw bytes.
 byte[] getValue(int index)
          Look up a key in the TXT record by zero-based index and return its value.
 byte[] getValue(java.lang.String forKey)
          Get the value associated with a key.
 java.lang.String getValueAsString(int index)
          Converts the result of getValue() to a string in the platform default character set.
 java.lang.String getValueAsString(java.lang.String forKey)
          Converts the result of getValue() to a string in the platform default character set.
 int remove(java.lang.String key)
          Remove a key/value pair from the TXT record.
 void set(java.lang.String key, byte[] value)
          Set a key/value pair in the TXT record.
 void set(java.lang.String key, java.lang.String value)
          Set a key/value pair in the TXT record.
 int size()
          Return the number of keys in the TXT record.
 java.lang.String toString()
          Return a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TXTRecord

public TXTRecord()
Constructs a new, empty TXT record.


TXTRecord

public TXTRecord(byte[] initBytes)
Constructs a new TXT record from a byte array in the standard format.

Method Detail

set

public void set(java.lang.String key,
                java.lang.String value)
Set a key/value pair in the TXT record. Setting an existing key will replace its value.

Parameters:
key - The key name. Must be ASCII, with no '=' characters.

value - Value to be encoded into bytes using the default platform character set.

set

public void set(java.lang.String key,
                byte[] value)
Set a key/value pair in the TXT record. Setting an existing key will replace its value.

Parameters:
key - The key name. Must be ASCII, with no '=' characters.

value - Binary representation of the value.

remove

public int remove(java.lang.String key)
Remove a key/value pair from the TXT record. Returns index it was at, or -1 if not found.


size

public int size()
Return the number of keys in the TXT record.


contains

public boolean contains(java.lang.String key)
Return true if key is present in the TXT record, false if not.


getKey

public java.lang.String getKey(int index)
Return a key in the TXT record by zero-based index. Returns null if index exceeds the total number of keys.


getValue

public byte[] getValue(int index)
Look up a key in the TXT record by zero-based index and return its value.

Returns null if index exceeds the total number of keys. Returns null if the key is present with no value.


getValueAsString

public java.lang.String getValueAsString(int index)
Converts the result of getValue() to a string in the platform default character set.


getValue

public byte[] getValue(java.lang.String forKey)
Get the value associated with a key. Will be null if the key is not defined. Array will have length 0 if the key is defined with an = but no value.

Parameters:
forKey - The left-hand side of the key-value pair.

Returns:
The binary representation of the value.

getValueAsString

public java.lang.String getValueAsString(java.lang.String forKey)
Converts the result of getValue() to a string in the platform default character set.

Parameters:
forKey - The left-hand side of the key-value pair.

Returns:
The value represented in the default platform character set.

getRawBytes

public byte[] getRawBytes()
Return the contents of the TXT record as raw bytes.


toString

public java.lang.String toString()
Return a string representation of the object.

Overrides:
toString in class java.lang.Object