3131
3232import org .apache .log4j .Logger ;
3333
34- import com .cloud .utils .NumbersUtil ;
35-
3634/**
37- * copied from the public domain utility from John Burkard .
38- * @author <a href="mailto:[email protected] ">Johann Burkard</a> 39- * @version 2.1.3
35+ * This class retrieves the (first) MAC address for the machine is it is loaded on and stores it statically for retrieval .
36+ * It can also be used for formatting MAC addresses.
37+ * copied fnd addpeted rom the public domain utility from John Burkard.
4038 **/
4139public class MacAddress {
4240 private static final Logger s_logger = Logger .getLogger (MacAddress .class );
@@ -70,19 +68,6 @@ public String toString(String separator) {
7068 formatter .format ("%02x%s%02x%s%02x%s%02x%s%02x%s%02x" , _addr >> 40 & 0xff , separator , _addr >> 32 & 0xff , separator , _addr >> 24 & 0xff , separator ,
7169 _addr >> 16 & 0xff , separator , _addr >> 8 & 0xff , separator , _addr & 0xff );
7270 return buff .toString ();
73-
74- /*
75-
76- String str = Long.toHexString(_addr);
77-
78- for (int i = str.length() - 1; i >= 0; i--) {
79- buff.append(str.charAt(i));
80- if (separator != null && (str.length() - i) % 2 == 0) {
81- buff.append(separator);
82- }
83- }
84- return buff.reverse().toString();
85- */
8671 }
8772
8873 @ Override
@@ -242,13 +227,6 @@ static String parse(String in) {
242227 return null ;
243228 }
244229
245- public static void main (String [] args ) {
246- MacAddress addr = MacAddress .getMacAddress ();
247- System .out .println ("addr in integer is " + addr .toLong ());
248- System .out .println ("addr in bytes is " + NumbersUtil .bytesToString (addr .toByteArray (), 0 , addr .toByteArray ().length ));
249- System .out .println ("addr in char is " + addr .toString (":" ));
250- }
251-
252230 /**
253231 * Parses a <code>long</code> from a hex encoded number. This method will skip
254232 * all characters that are not 0-9 and a-f (the String is lower cased first).
@@ -258,7 +236,7 @@ public static void main(String[] args) {
258236 * @return a <code>long</code>
259237 * @throws NullPointerException if the String is <code>null</code>
260238 */
261- public static long parseLong (String s ) throws NullPointerException {
239+ private static long parseLong (String s ) throws NullPointerException {
262240 s = s .toLowerCase ();
263241 long out = 0 ;
264242 byte shifts = 0 ;
@@ -278,35 +256,6 @@ public static long parseLong(String s) throws NullPointerException {
278256 return out ;
279257 }
280258
281- /**
282- * Parses an <code>int</code> from a hex encoded number. This method will skip
283- * all characters that are not 0-9 and a-f (the String is lower cased first).
284- * Returns 0 if the String does not contain any interesting characters.
285- *
286- * @param s the String to extract an <code>int</code> from, may not be <code>null</code>
287- * @return an <code>int</code>
288- * @throws NullPointerException if the String is <code>null</code>
289- */
290- public static int parseInt (String s ) throws NullPointerException {
291- s = s .toLowerCase ();
292- int out = 0 ;
293- byte shifts = 0 ;
294- char c ;
295- for (int i = 0 ; i < s .length () && shifts < 8 ; i ++) {
296- c = s .charAt (i );
297- if ((c > 47 ) && (c < 58 )) {
298- out <<= 4 ;
299- ++shifts ;
300- out |= c - 48 ;
301- } else if ((c > 96 ) && (c < 103 )) {
302- ++shifts ;
303- out <<= 4 ;
304- out |= c - 87 ;
305- }
306- }
307- return out ;
308- }
309-
310259 /**
311260 * Parses a <code>short</code> from a hex encoded number. This method will skip
312261 * all characters that are not 0-9 and a-f (the String is lower cased first).
@@ -316,7 +265,7 @@ public static int parseInt(String s) throws NullPointerException {
316265 * @return a <code>short</code>
317266 * @throws NullPointerException if the String is <code>null</code>
318267 */
319- public static short parseShort (String s ) throws NullPointerException {
268+ private static short parseShort (String s ) throws NullPointerException {
320269 s = s .toLowerCase ();
321270 short out = 0 ;
322271 byte shifts = 0 ;
@@ -335,33 +284,4 @@ public static short parseShort(String s) throws NullPointerException {
335284 }
336285 return out ;
337286 }
338-
339- /**
340- * Parses a <code>byte</code> from a hex encoded number. This method will skip
341- * all characters that are not 0-9 and a-f (the String is lower cased first).
342- * Returns 0 if the String does not contain any interesting characters.
343- *
344- * @param s the String to extract a <code>byte</code> from, may not be <code>null</code>
345- * @return a <code>byte</code>
346- * @throws NullPointerException if the String is <code>null</code>
347- */
348- public static byte parseByte (String s ) throws NullPointerException {
349- s = s .toLowerCase ();
350- byte out = 0 ;
351- byte shifts = 0 ;
352- char c ;
353- for (int i = 0 ; i < s .length () && shifts < 2 ; i ++) {
354- c = s .charAt (i );
355- if ((c > 47 ) && (c < 58 )) {
356- out <<= 4 ;
357- ++shifts ;
358- out |= c - 48 ;
359- } else if ((c > 96 ) && (c < 103 )) {
360- ++shifts ;
361- out <<= 4 ;
362- out |= c - 87 ;
363- }
364- }
365- return out ;
366- }
367287}
0 commit comments