com.fasterxml.uuid
Class EthernetAddress

java.lang.Object
  extended by com.fasterxml.uuid.EthernetAddress
All Implemented Interfaces:
Serializable, Cloneable, Comparable<EthernetAddress>

public class EthernetAddress
extends Object
implements Serializable, Cloneable, Comparable<EthernetAddress>

EthernetAddress encapsulates the 6-byte MAC address defined in IEEE 802.1 standard.

See Also:
Serialized Form

Field Summary
protected  long _address
          48-bit MAC address, stored in 6 lowest-significant bytes (in big endian notation)
protected static Random _rnd
          We may need a random number generator, for creating dummy ethernet address if no real interface is found.
 
Constructor Summary
EthernetAddress(byte[] addr)
          Binary constructor that constructs an instance given the 6 byte (48-bit) address.
EthernetAddress(long addr)
          Another binary constructor; constructs an instance from the given long argument; the lowest 6 bytes contain the address.
EthernetAddress(String addrStr)
          String constructor; given a 'standard' ethernet MAC address string (like '00:C0:F0:3D:5B:7C'), constructs an EthernetAddress instance.
 
Method Summary
protected static Random _randomNumberGenerator()
          Helper method for accessing configured random number generator
 byte[] asByteArray()
          Returns 6 byte byte array that contains the binary representation of this ethernet address; byte 0 is the most significant byte (and so forth)
 Object clone()
          Default cloning behaviour (bitwise copy) is just fine...
 int compareTo(EthernetAddress other)
          Method that compares this EthernetAddress to one passed in as argument.
static EthernetAddress constructMulticastAddress()
          Factory method that can be used to construct a random multicast address; to be used in cases where there is no "real" ethernet address to use.
static EthernetAddress constructMulticastAddress(Random rnd)
          Factory method that can be used to construct a random multicast address; to be used in cases where there is no "real" ethernet address to use.
 boolean equals(Object o)
           
static EthernetAddress fromInterface()
          Factory method that locates a network interface that has a suitable mac address (ethernet cards, and things that emulate one), and return that address.
 boolean isLocallyAdministeredAddress()
          Method that can be used to check if this address refers to a "locally administered address" (see [http://en.wikipedia.org/wiki/MAC_address] for details).
 boolean isMulticastAddress()
          Method that can be used to check if this address refers to a multicast address.
 byte[] toByteArray()
          Synonym to 'asByteArray()'
 void toByteArray(byte[] array)
           
 void toByteArray(byte[] array, int pos)
           
 long toLong()
           
 String toString()
          Returns the canonical string representation of this ethernet address.
static EthernetAddress valueOf(byte[] addr)
          Constructs a new EthernetAddress given the byte array that contains binary representation of the address.
static EthernetAddress valueOf(int[] addr)
          Constructs a new EthernetAddress given the byte array that contains binary representation of the address.
static EthernetAddress valueOf(long addr)
          Constructs a new EthernetAddress given the long int value (64-bit) representation of the ethernet address (of which 48 LSB contain the definition) Note that calling this method returns the same result as would using the matching constructor.
static EthernetAddress valueOf(String addrStr)
          Constructs a new EthernetAddress given a string representation of the ethernet address.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_rnd

protected static Random _rnd
We may need a random number generator, for creating dummy ethernet address if no real interface is found.


_address

protected final long _address
48-bit MAC address, stored in 6 lowest-significant bytes (in big endian notation)

Constructor Detail

EthernetAddress

public EthernetAddress(String addrStr)
                throws NumberFormatException
String constructor; given a 'standard' ethernet MAC address string (like '00:C0:F0:3D:5B:7C'), constructs an EthernetAddress instance. Note that string is case-insensitive, and also that leading zeroes may be omitted. Thus '00:C0:F0:3D:5B:7C' and '0:c0:f0:3d:5b:7c' are equivalent, and a 'null' address could be passed as ':::::' as well as '00:00:00:00:00:00' (or any other intermediate combination).

Parameters:
addrStr - String representation of the ethernet address
Throws:
NumberFormatException

EthernetAddress

public EthernetAddress(byte[] addr)
                throws NumberFormatException
Binary constructor that constructs an instance given the 6 byte (48-bit) address. Useful if an address is saved in binary format (for saving space for example).

Throws:
NumberFormatException

EthernetAddress

public EthernetAddress(long addr)
Another binary constructor; constructs an instance from the given long argument; the lowest 6 bytes contain the address.

Parameters:
addr - long that contains the MAC address in 6 least significant bytes.
Method Detail

clone

public Object clone()
Default cloning behaviour (bitwise copy) is just fine...

Overrides:
clone in class Object

valueOf

public static EthernetAddress valueOf(byte[] addr)
                               throws NumberFormatException
Constructs a new EthernetAddress given the byte array that contains binary representation of the address. Note that calling this method returns the same result as would using the matching constructor.

Parameters:
addr - Binary representation of the ethernet address
Throws:
NumberFormatException - if addr is invalid (less or more than 6 bytes in array)

valueOf

public static EthernetAddress valueOf(int[] addr)
                               throws NumberFormatException
Constructs a new EthernetAddress given the byte array that contains binary representation of the address. Note that calling this method returns the same result as would using the matching constructor.

Parameters:
addr - Binary representation of the ethernet address
Throws:
NumberFormatException - if addr is invalid (less or more than 6 ints in array)

valueOf

public static EthernetAddress valueOf(String addrStr)
                               throws NumberFormatException
Constructs a new EthernetAddress given a string representation of the ethernet address. Note that calling this method returns the same result as would using the matching constructor.

Parameters:
addrStr - String representation of the ethernet address
Throws:
NumberFormatException - if addr representation is invalid

valueOf

public static EthernetAddress valueOf(long addr)
Constructs a new EthernetAddress given the long int value (64-bit) representation of the ethernet address (of which 48 LSB contain the definition) Note that calling this method returns the same result as would using the matching constructor.

Parameters:
addr - Long int representation of the ethernet address

fromInterface

public static EthernetAddress fromInterface()
Factory method that locates a network interface that has a suitable mac address (ethernet cards, and things that emulate one), and return that address. If there are multiple applicable interfaces, one of them is returned; which one is returned is not specified. Method is meant for accessing an address needed to construct generator for time+location based UUID generation method.

Returns:
Ethernet address of one of interfaces system has; not including local or loopback addresses; if one exists, null if no such interfaces are found.

constructMulticastAddress

public static EthernetAddress constructMulticastAddress()
Factory method that can be used to construct a random multicast address; to be used in cases where there is no "real" ethernet address to use. Address to generate should be a multicase address to avoid accidental collision with real manufacturer-assigned MAC addresses.

Internally a SecureRandom instance is used for generating random number to base address on.


constructMulticastAddress

public static EthernetAddress constructMulticastAddress(Random rnd)
Factory method that can be used to construct a random multicast address; to be used in cases where there is no "real" ethernet address to use. Address to generate should be a multicase address to avoid accidental collision with real manufacturer-assigned MAC addresses.

Address is created using specified random number generator.


asByteArray

public byte[] asByteArray()
Returns 6 byte byte array that contains the binary representation of this ethernet address; byte 0 is the most significant byte (and so forth)

Returns:
6 byte byte array that contains the binary representation

toByteArray

public byte[] toByteArray()
Synonym to 'asByteArray()'

Returns:
6 byte byte array that contains the binary representation

toByteArray

public void toByteArray(byte[] array)

toByteArray

public void toByteArray(byte[] array,
                        int pos)

toLong

public long toLong()

isMulticastAddress

public boolean isMulticastAddress()
Method that can be used to check if this address refers to a multicast address. Such addresses are never assigned to individual network cards.


isLocallyAdministeredAddress

public boolean isLocallyAdministeredAddress()
Method that can be used to check if this address refers to a "locally administered address" (see [http://en.wikipedia.org/wiki/MAC_address] for details). Such addresses are not assigned to individual network cards.


equals

public boolean equals(Object o)
Overrides:
equals in class Object

compareTo

public int compareTo(EthernetAddress other)
Method that compares this EthernetAddress to one passed in as argument. Comparison is done simply by comparing individual address bytes in the order.

Specified by:
compareTo in interface Comparable<EthernetAddress>
Returns:
negative number if this EthernetAddress should be sorted before the parameter address if they are equal, os positive non-zero number if this address should be sorted after parameter

toString

public String toString()
Returns the canonical string representation of this ethernet address. Canonical means that all characters are lower-case and string length is always 17 characters (ie. leading zeroes are not omitted).

Overrides:
toString in class Object
Returns:
Canonical string representation of this ethernet address.

_randomNumberGenerator

protected static Random _randomNumberGenerator()
Helper method for accessing configured random number generator



Copyright © 2011 FasterXML.com. All Rights Reserved.