Source:
<code>private void enableNotifications() { logger.debug("Enabling notifications for device '{}'", device.getAddress()); device.enableRSSINotifications(n -> { rssi = (int) n; BluetoothScanNotification notification = new BluetoothScanNotification(); notification.setRssi(n); notifyListeners(BluetoothEventType.SCAN_RECORD, notification); }); device.enableManufacturerDataNotifications(n -> { for (Map.Entry<Short, byte[]> entry : n.entrySet()) { BluetoothScanNotification notification = new BluetoothScanNotification(); byte[] data = new byte[entry.getValue().length + 2]; data[0] = (byte) (entry.getKey() & 0xFF); <START> data[1] = (byte) (entry.getKey() >> 8); <END> System.arraycopy(entry.getValue(), 0, data, 2, entry.getValue().length); logger.debug("Received manufacturer data for '{}': {}", address, HexUtils.bytesToHexWithSpaces(data)); notification.setManufacturerData(data); notifyListeners(BluetoothEventType.SCAN_RECORD, notification); } }); device.enableConnectedNotifications(connected -> { connectionState = connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED; logger.debug("Connection state of '{}' changed to {}", address, connectionState); notifyListeners(BluetoothEventType.CONNECTION_STATE, new BluetoothConnectionStatusNotification(connectionState)); }); device.enableServicesResolvedNotifications(resolved -> { logger.debug("Received services resolved event for '{}': {}", address, resolved); if (resolved) { refreshServices(); notifyListeners(BluetoothEventType.SERVICES_DISCOVERED); } }); device.enableServiceDataNotifications(data -> { if (logger.isDebugEnabled()) { logger.debug("Received service data for '{}':", address); for (Map.Entry<String, byte[]> entry : data.entrySet()) { logger.debug("{} : {}", entry.getKey(), HexUtils.bytesToHexWithSpaces(entry.getValue())); } } }); }</code><technical_language>need erase unwanted bits & 0xFF00-ing & 0xFF-ing shift</technical_language>

Target:
private void enableNotifications() { logger.debug("Enabling notifications for device '{}'", device.getAddress()); device.enableRSSINotifications(n -> { rssi = (int) n; BluetoothScanNotification notification = new BluetoothScanNotification(); notification.setRssi(n); notifyListeners(BluetoothEventType.SCAN_RECORD, notification); }); device.enableManufacturerDataNotifications(n -> { for (Map.Entry<Short, byte[]> entry : n.entrySet()) { BluetoothScanNotification notification = new BluetoothScanNotification(); byte[] data = new byte[entry.getValue().length + 2]; data[0] = (byte) (entry.getKey() & 0xFF); data[1] = (byte) (entry.getKey() >>> 8); System.arraycopy(entry.getValue(), 0, data, 2, entry.getValue().length); if (logger.isDebugEnabled()) { logger.debug("Received manufacturer data for '{}': {}", address, HexUtils.bytesToHex(data, " ")); } notification.setManufacturerData(data); notifyListeners(BluetoothEventType.SCAN_RECORD, notification); } }); device.enableConnectedNotifications(connected -> { connectionState = connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED; logger.debug("Connection state of '{}' changed to {}", address, connectionState); notifyListeners(BluetoothEventType.CONNECTION_STATE, new BluetoothConnectionStatusNotification(connectionState)); }); device.enableServicesResolvedNotifications(resolved -> { logger.debug("Received services resolved event for '{}': {}", address, resolved); if (resolved) { refreshServices(); notifyListeners(BluetoothEventType.SERVICES_DISCOVERED); } }); device.enableServiceDataNotifications(data -> { if (logger.isDebugEnabled()) { logger.debug("Received service data for '{}':", address); for (Map.Entry<String, byte[]> entry : data.entrySet()) { logger.debug("{} : {}", entry.getKey(), HexUtils.bytesToHex(entry.getValue(), " ")); } } }); }