JXTA

net.jxta.impl.id.binaryID
Class BinaryID

java.lang.Object
  extended by net.jxta.impl.id.binaryID.BinaryID
All Implemented Interfaces:
Serializable

public class BinaryID
extends Object
implements Serializable

A BinaryID is a 256-byte, identifier. This class should be immutable so that it is thread safe.

Author:
Daniel Brookshier turbogeek@cluck.com
See Also:
ID, IDFactory, Serialized Form

Field Summary
static int dataOffset
          location of the byte where the data starts.
protected  String encodedValue
          Array that holds the length and the value of the id in base64 format.
static byte flagCodatID
           
static byte flagGenericID
           
static byte flagModuleClassID
           
static byte flagModuleClassRoleID
           
static byte flagModuleSpecID
           
static byte flagPeerGroupID
           
static byte flagPeerID
           
static byte flagPipeID
           
static int flagsOffset
          location of the byte designating its type.
static int flagsSize
           
static BinaryID nullBinaryID
           
static String UUIDEncoded
           
 
Constructor Summary
  BinaryID()
          Creates a null value ID.
  BinaryID(byte id)
          Creates zero content ID of a specific type.
  BinaryID(byte type, byte[] data, boolean lengthIncluded)
          Simple constructor that takes a binary array to signify the contents of the array.
protected BinaryID(String encodedValue)
          Creates a ID from a string.
 
Method Summary
 String encodedValue()
           
 boolean equals(Object target)
          Compares two BinaryIDs for equality.
 String getID()
          returns the raw encoded value.
 int hashCode()
          Returns the hash code of the BinaryID

WARNING: Do not use this hash as a network ID.

 byte[] toByteArray()
          Returns the value of the ID as a binary array.
 byte[] toSizeIncludedByteArray()
          Returns the value of the ID as a binary array without the size in byte zero.
 String toString()
          Returns base 64 encoded value.
 byte type()
          Return the type of ID.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UUIDEncoded

public static String UUIDEncoded

flagsSize

public static final int flagsSize
See Also:
Constant Field Values

flagPeerGroupID

public static final byte flagPeerGroupID
See Also:
Constant Field Values

flagPeerID

public static final byte flagPeerID
See Also:
Constant Field Values

flagPipeID

public static final byte flagPipeID
See Also:
Constant Field Values

flagModuleClassID

public static final byte flagModuleClassID
See Also:
Constant Field Values

flagModuleClassRoleID

public static final byte flagModuleClassRoleID
See Also:
Constant Field Values

flagModuleSpecID

public static final byte flagModuleSpecID
See Also:
Constant Field Values

flagCodatID

public static final byte flagCodatID
See Also:
Constant Field Values

flagGenericID

public static final byte flagGenericID
See Also:
Constant Field Values

flagsOffset

public static final int flagsOffset
location of the byte designating its type.

See Also:
Constant Field Values

dataOffset

public static final int dataOffset
location of the byte where the data starts.

See Also:
Constant Field Values

nullBinaryID

public static final BinaryID nullBinaryID

encodedValue

protected String encodedValue
Array that holds the length and the value of the id in base64 format. This is the default format rather than binary byte because it saves time converting. Odds of returning the actual binary are low so it is done on demand only. Callers of the toByteArray() method should consider the cost of decoding if it is to be called often.

Constructor Detail

BinaryID

public BinaryID()
Creates a null value ID.


BinaryID

public BinaryID(byte id)
Creates zero content ID of a specific type.


BinaryID

protected BinaryID(String encodedValue)
Creates a ID from a string. Note that the ID is not currently validated.

Parameters:
encodedValue - Value to convert ID.

BinaryID

public BinaryID(byte type,
                byte[] data,
                boolean lengthIncluded)
Simple constructor that takes a binary array to signify the contents of the array.

Parameters:
type - The Type of ID. Valid values: flagPeerGroupID,flagPeerID,flagPipeID,flagGenericID
data - the array of up to 256 bytes. Max is 256 if lengthIncluded is true or 255 if the first byte is the length-1.
lengthIncluded - Boolean that signifies if the first byte is the length of the bytes to follow.
Throws:
RuntimeException - Runtime exception trhown if array is not correct or if included, the array length does not match actual size.
Method Detail

toByteArray

public byte[] toByteArray()
Returns the value of the ID as a binary array. This is always decoded from the base64 string rather than caching of the binary array. Callers of the toByteArray() method should consider the cost of decoding if the method is called often.

Returns:
returns the data part of the array.

toSizeIncludedByteArray

public byte[] toSizeIncludedByteArray()
Returns the value of the ID as a binary array without the size in byte zero. This is always decoded from the base64 string rather than caching of the binary array. Callers of the toByteArray() method should consider the cost of decoding if the method is called often.

Note that we assume the array size-1 equals the contents of byte zero.

Returns:
returns the array with the first byte as the length of the remaining bytes.

encodedValue

public String encodedValue()
Returns:
The ID which consists of a character designating type, followed by the base64 encoded value of the size and array of bytes.

hashCode

public int hashCode()
Returns the hash code of the BinaryID

WARNING: Do not use this hash as a network ID. Use a stronger digest hash like SHA-1 to get the hash of the contents.

Overrides:
hashCode in class Object
Returns:
int hashcode

equals

public boolean equals(Object target)
Compares two BinaryIDs for equality.

true: taget == this

false: target == null

true: taget.encodedValue == this.encodedValue

true: target instance of ID && ID==ID.nullID && nullBinaryID.encodedValue().equals( encodedValue())

false: all other posibilities

Overrides:
equals in class Object
Parameters:
target - the BidaryID to be compared against.
Returns:
boolean true if IDs are equal, false otherwise.

type

public byte type()
Return the type of ID.

Returns:
byte value designating type.

toString

public String toString()
Returns base 64 encoded value.

Overrides:
toString in class Object
Returns:
String return value

getID

public String getID()
returns the raw encoded value. Not cloned because it is a string.


JXSE