public final class MacAddress extends CacheableDataType implements Comparable<MacAddress>
All constructors for this class are private. Creating instances
of MacAddress is done via the static methods on the class.
Instances of this class are immutable, making them inherently threadsafe.
This class overrides equals(java.lang.Object) and hashCode() so that instances
play nicely with the Collection classes.
This class implements the Comparable interface to ensure that a
sorted list of addresses is presented in an intuitive order.
| Modifier and Type | Class and Description |
|---|---|
static class |
MacAddress.Format
Designates the different MAC address string formats available.
|
| Modifier and Type | Field and Description |
|---|---|
static MacAddress |
BROADCAST
The broadcast address, that is ff:ff:ff:ff:ff:ff.
|
static int |
MAC_ADDR_SIZE
Number of bytes for a MAC address.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(MacAddress o)
Implements the Comparable interface, to return addresses in
natural order.
|
boolean |
equals(Object o) |
String |
getEthernetCompany()
Returns the ethernet company name that this MAC address is associated
with.
|
int |
hashCode() |
void |
intoBuffer(ByteBuffer b)
Writes the bytes that represent the MAC address directly into
ByteBuffer at the buffer's current position. |
boolean |
isBroadcast()
Returns true if this is the broadcast address (FF:FF:FF:FF:FF:FF).
|
boolean |
isMulticast()
Returns true if this is a multicast address.
|
byte[] |
toByteArray()
Returns a newly allocated byte array containing bytes that represent
the MAC address.
|
String |
toFormattedString(MacAddress.Format fmt)
Returns a string representation of this MAC address, using the
specified
MacAddress.Format. |
String |
toFormattedString(MacAddress.Format fmt,
boolean toLowerCase)
Returns a string representation of this MAC address, using the
specified
MacAddress.Format. |
long |
toLong()
Returns the MAC address represented as a long.
|
String |
toString()
Returns a string representation of this MAC address
in "XX:XX:XX:XX:XX:XX" form.
|
static MacAddress |
valueFrom(ByteBuffer buffer)
Reads 6 bytes from the specified byte buffer and creates a MAC address
entity.
|
static MacAddress |
valueOf(byte[] macBytes)
Returns an object that represents the value of the MAC address defined
by the specified address bytes.
|
static MacAddress |
valueOf(long encodedAddress)
Returns an object that represents the value of the MAC address encoded
by the specified long value.
|
static MacAddress |
valueOf(String address)
Returns an object that represents the value of the MAC address defined
by the specified string.
|
getRefQ, keyFromBytespublic static final int MAC_ADDR_SIZE
public static final MacAddress BROADCAST
public String getEthernetCompany()
A value of "(Unknown)" will be returned if no known mapping exists.
public String toString()
This is the same result as invoking
macAddr.toFormattedString(MacAddress.Format.MULTI_COLON).
public String toFormattedString(MacAddress.Format fmt)
MacAddress.Format.
fmt - the format to usepublic String toFormattedString(MacAddress.Format fmt, boolean toLowerCase)
MacAddress.Format.
fmt - the format to usetoLowerCase - if true, hex digits will be lowercasepublic boolean isBroadcast()
public boolean isMulticast()
public byte[] toByteArray()
public void intoBuffer(ByteBuffer b)
ByteBuffer at the buffer's current position. Note that the
address bytes are in network byte order; that is, the highest order byte
of the address is at index 0.b - the byte buffer to write intopublic long toLong()
This method is provided to support the encoding of MAC addresses as long values.
public int compareTo(MacAddress o)
compareTo in interface Comparable<MacAddress>o - the other MAC addressComparable.compareTo(T)public static MacAddress valueOf(byte[] macBytes)
macBytes - the MAC address bytesNullPointerException - if macBytes is nullufferIllegalArgumentException - if macBytes is not 6 bytes in lengthpublic static MacAddress valueOf(String address)
Acceptable input formats are:
address - the string representation of the MAC addressNullPointerException - if address is nullIllegalArgumentException - if address is not an acceptable formatpublic static MacAddress valueOf(long encodedAddress)
encodedAddress - the encoded MAC addressIllegalArgumentException - if the specified long is not a valid
encodementpublic static MacAddress valueFrom(ByteBuffer buffer)
buffer - byte buffer from which to read the bytesBufferUnderflowException - if the buffer does not have 6 bytes
remainingCopyright © 2014. All Rights Reserved.