function onDeviceReady() { cordova.exec(null, null, "SplashScreen", "hide", []); window.MacAddress = new MacAddress(); window.MacAddress.getMacAddress(function(result){ database._mac_address = result.mac; }, function(){ database._mac_address = '01:02:03:04:05:06'; }); }
/** * Returns a MAC address instance representing the specified {@code long} * value. The lower 48 bits of the long value are used to parse as a MAC * address. * * @param address the long value to be parsed. The lower 48 bits are used for a * MAC address. * @return a MAC address instance representing the specified {@code long} * value. * @throws IllegalArgumentException if the long value cannot be parsed as a MAC address. */ public static MacAddress valueOf(final long address) { final byte[] addressInBytes = new byte[]{ (byte) (address >> 40 & 0xff), (byte) (address >> 32 & 0xff), (byte) (address >> 24 & 0xff), (byte) (address >> 16 & 0xff), (byte) (address >> 8 & 0xff), (byte) (address >> 0 & 0xff)}; return new MacAddress(addressInBytes); }
/** * Returns a MAC address instance representing the specified {@code byte} * array. * * @param address the byte array to be parsed. * @return a MAC address instance representing the specified {@code byte} * array. * @throws IllegalArgumentException if the byte array cannot be parsed as a MAC address. */ public static MacAddress valueOf(final byte[] address) { if (address.length != MacAddress.MAC_ADDRESS_LENGTH) { throw new IllegalArgumentException("the length is not " + MacAddress.MAC_ADDRESS_LENGTH); } return new MacAddress(address); }
public MacAddress getChassisIdByMac() { ByteBuffer portBB = ByteBuffer.wrap(this.getChassisId().getValue()); byte type = portBB.get(); if (type == CHASSIS_TLV_SUBTYPE) { byte[] bytes = new byte[portBB.remaining()]; System.arraycopy(portBB.array(), portBB.position(), bytes, 0, MacAddress.MAC_ADDRESS_LENGTH); return new MacAddress(bytes); } else { return MacAddress.NONE; } }
/** * Returns a MAC address instance representing the value of the specified * {@code String}. * * @param address the String representation of the MAC Address to be parsed. * @return a MAC Address instance representing the value of the specified * {@code String}. * @throws IllegalArgumentException if the string cannot be parsed as a MAC address. */ public static MacAddress valueOf(final String address) { if (!isValid(address)) { throw new IllegalArgumentException( "Specified MAC Address must contain 12 hex digits" + " separated pairwise by :'s."); } final String[] elements = address.split(":"); final byte[] addressInBytes = new byte[MacAddress.MAC_ADDRESS_LENGTH]; for (int i = 0; i < MacAddress.MAC_ADDRESS_LENGTH; i++) { final String element = elements[i]; addressInBytes[i] = (byte) Integer.parseInt(element, 16); } return new MacAddress(addressInBytes); }
session = Db.getSession(); Transaction tx = null; try { tx = session.beginTransaction(); License license = getLicense(session, licenseStr); List<MacAddress> macAddresses = license.getMacAddresses(); for(MacAddress mac:macAddresses) { if(mac.getMacAddress().equals(macAddress)) { return; } } MacAddress mac = new MacAddress(); mac.setMacAddress(macAddress); license.getMacAddresses().add(mac); tx.commit(); } catch (RuntimeException e) { if (tx != null) tx.rollback(); throw e; // or display error message } finally { session.close(); }