@TargetApi(LOLLIPOP) private BonjourEvent newBonjourEvent(BonjourEvent.Type type,NsdServiceInfo serviceInfo){
  BonjourService.Builder serviceBuilder=new BonjourService.Builder(serviceInfo.getServiceName(),serviceInfo.getServiceType());
  if (Build.VERSION.SDK_INT >= LOLLIPOP) {
    Map<String,byte[]> attributes=serviceInfo.getAttributes();
    for (    String key : attributes.keySet()) {
      serviceBuilder.addTxtRecord(key,new String(attributes.get(key),Charset.forName("UTF-8")));
    }
  }
  serviceBuilder.addAddress(serviceInfo.getHost());
  serviceBuilder.setPort(serviceInfo.getPort());
  return new BonjourEvent(type,serviceBuilder.build());
}

@ TargetApi ( LOLLIPOP ) private BonjourEvent newBonjourEvent ( BonjourEvent . Type type , NsdServiceInfo serviceInfo ) { BonjourService . Builder serviceBuilder = new BonjourService . Builder ( serviceInfo . getServiceName ( ) , serviceInfo . getServiceType ( ) ) ; if ( Build . VERSION . SDK_INT >= LOLLIPOP ) { Map < String , byte [ ] > attributes = serviceInfo . getAttributes ( ) ; for ( String key : attributes . keySet ( ) ) { serviceBuilder . addTxtRecord ( key , new String ( attributes . get ( key ) , Charset . forName ( "UTF-8" ) ) ) ; } } serviceBuilder . addAddress ( serviceInfo . getHost ( ) ) ; serviceBuilder . setPort ( serviceInfo . getPort ( ) ) ; return new BonjourEvent ( type , serviceBuilder . build ( ) ) ; }
creates a new bonjourevent instance from an nsd service info object .
