Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
24 package org.direct_bt;
26 import java.util.Arrays;
33 public static final EUI48Sub ANY_DEVICE =
new EUI48Sub(
new byte[] { (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00 }, 0, 6 );
35 public static final EUI48Sub ALL_DEVICE =
new EUI48Sub(
new byte[] { (byte)0xff, (
byte)0xff, (byte)0xff, (
byte)0xff, (byte)0xff, (
byte)0xff }, 0, 6 );
37 public static final EUI48Sub LOCAL_DEVICE =
new EUI48Sub(
new byte[] { (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0xff, (byte)0xff, (
byte)0xff }, 0, 6 );
42 public final byte b[];
44 private volatile int hash;
65 final int str_len = str.length();
69 errmsg.append(
"EUI48 sub-string must be less or equal length 17 but "+str.length()+
": "+str);
72 final byte b_[] =
new byte[ 6 ];
76 boolean exp_colon =
false;
77 while( j+1 < str_len ) {
78 final boolean is_colon =
':' == str.charAt(j);
79 if( exp_colon && !is_colon ) {
80 errmsg.append(
"EUI48Sub sub-string not in format '01:02:03:0A:0B:0C', but '"+str+
"', colon missing, pos "+j+
", len "+str_len);
82 }
else if( is_colon ) {
86 b_[len_] = Integer.valueOf(str.substring(j, j+2), 16).byteValue();
93 for(j=0; j<len_; ++j) {
94 dest.
b[j] = b_[len_-1-j];
96 }
catch (
final NumberFormatException e) {
97 errmsg.append(
"EUI48 sub-string not in format '01:02:03:0A:0B:0C' but "+str+
", pos "+j+
", len "+str_len);
119 public EUI48Sub(
final String str)
throws IllegalArgumentException {
120 final StringBuilder errmsg =
new StringBuilder();
123 throw new IllegalArgumentException(errmsg.toString());
128 public EUI48Sub(
final byte stream[],
final int pos,
final int len_) {
129 if( len_ >
EUI48.byte_size || pos + len_ > stream.length ) {
130 throw new IllegalArgumentException(
"EUI48 stream ( pos "+pos+
", len "+len_+
" > EUI48 size "+
EUI48.byte_size+
" or stream.length "+stream.length);
133 System.arraycopy(stream, pos,
b, 0, len_);
138 public final boolean equals(
final Object obj) {
142 if (obj ==
null || !(obj instanceof
EUI48Sub)) {
145 final int length2 = ((
EUI48Sub)obj).length;
149 final byte[] b2 = ((
EUI48Sub)obj).b;
150 return Arrays.equals(
b, 0,
length, b2, 0, length2);
166 for(
int i=0; i<
length; i++) {
167 h = ( ( h << 5 ) - h ) +
b[i];
186 b[0] = 0;
b[1] = 0;
b[2] = 0;
187 b[3] = 0;
b[4] = 0;
b[5] = 0;
199 public static int indexOf(
final byte haystack_b[],
final int haystack_length,
200 final byte needle_b[],
final int needle_length) {
201 if( 0 == needle_length ) {
204 if( haystack_length < needle_length ) {
207 final byte first = needle_b[0];
208 final int outerEnd = haystack_length - needle_length + 1;
210 for (
int i = 0; i < outerEnd; i++) {
212 while( haystack_b[i] != first ) {
213 if( ++i == outerEnd ) {
219 final int innerEnd = i + needle_length;
222 if( ++j == innerEnd ) {
225 }
while( haystack_b[j] == needle_b[++k] );
264 final StringBuilder sb =
new StringBuilder(3 *
length - 1);
265 for(
int i=
length-1; 0 <= i; i--) {
271 return sb.toString();
273 return new String(
":");
void clearHash()
Method clears the cached hash value.
EUI48Sub()
Construct empty unset instance.
A 48 bit EUI-48 sub-identifier, see EUI48.
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
static final EUI48Sub ANY_DEVICE
EUI48Sub MAC address matching any device, i.e.
final byte b[]
The EUI48 sub-address, always 6 bytes reserved.
boolean contains(final EUI48Sub needle)
Returns true, if given EUI48Sub needle is contained in this instance haystack.
static final EUI48Sub ALL_DEVICE
EUI48Sub MAC address matching all device, i.e.
final boolean equals(final Object obj)
void clear()
Method clears the underlying byte array b and sets length to zero.
EUI48Sub(final byte stream[], final int pos, final int len_)
Construct instance via given source byte array.
static StringBuilder byteHexString(final StringBuilder sb, final byte value, final boolean lowerCase)
Produce a hexadecimal string representation of the given byte value.
EUI48Sub(final String str)
Construct a sub EUI48 via given string representation.
int length
The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
static final EUI48Sub LOCAL_DEVICE
EUI48Sub MAC address matching local device, i.e.
static boolean scanEUI48Sub(final String str, final EUI48Sub dest, final StringBuilder errmsg)
Fills given EUI48Sub instance via given string representation.
static int indexOf(final byte haystack_b[], final int haystack_length, final byte needle_b[], final int needle_length)
Find index of needle within haystack.
int indexOf(final EUI48Sub needle)
Finds the index of given EUI48Sub needle within this instance haystack.