private static final byte[] toOctets(int identifier,String text){
  byte[] s=text.getBytes(StandardCharsets.UTF_8);
  byte[] base=OctetUtils.toOctets(AttributeType.VENDOR_SPECIFIC,identifier);
  int maxTextSpace=Attribute.MAX_ATTRIBUTE_LENGTH - base.length;
  byte[] octets;
  if (s.length > maxTextSpace) {
    octets=new byte[Attribute.MAX_ATTRIBUTE_LENGTH];
    System.arraycopy(s,0,octets,base.length,Attribute.MAX_ATTRIBUTE_LENGTH - base.length);
  }
 else {
    octets=new byte[base.length + s.length];
    System.arraycopy(s,0,octets,base.length,s.length);
  }
  System.arraycopy(base,0,octets,0,base.length);
  octets[1]=(byte)octets.length;
  return octets;
}

private static final byte [ ] toOctets ( int identifier , String text ) { byte [ ] s = text . getBytes ( StandardCharsets . UTF_8 ) ; byte [ ] base = OctetUtils . toOctets ( AttributeType . VENDOR_SPECIFIC , identifier ) ; int maxTextSpace = Attribute . MAX_ATTRIBUTE_LENGTH - base . length ; byte [ ] octets ; if ( s . length > maxTextSpace ) { octets = new byte [ Attribute . MAX_ATTRIBUTE_LENGTH ] ; System . arraycopy ( s , 0 , octets , base . length , Attribute . MAX_ATTRIBUTE_LENGTH - base . length ) ; } else { octets = new byte [ base . length + s . length ] ; System . arraycopy ( s , 0 , octets , base . length , s . length ) ; } System . arraycopy ( base , 0 , octets , 0 , base . length ) ; octets [ 1 ] = ( byte ) octets . length ; return octets ; }
custom implementation of tooctets to ensure a string value too long will be truncated properly in view of the space needed by the type , length , and identifier .
