public static final byte[] toOctets(AttributeType type,String str){
  final byte[] s=str.getBytes(StandardCharsets.UTF_8);
  byte[] octets;
  if (s.length > Attribute.MAX_ATTRIBUTE_VALUE_LENGTH) {
    octets=new byte[Attribute.MAX_ATTRIBUTE_LENGTH];
    octets[0]=(byte)type.getTypeCode();
    octets[1]=(byte)Attribute.MAX_ATTRIBUTE_LENGTH;
    System.arraycopy(s,0,octets,2,Attribute.MAX_ATTRIBUTE_VALUE_LENGTH);
  }
 else {
    octets=new byte[s.length + 2];
    octets[0]=(byte)type.getTypeCode();
    octets[1]=(byte)(s.length + 2);
    System.arraycopy(s,0,octets,2,s.length);
  }
  return octets;
}

public static final byte [ ] toOctets ( AttributeType type , String str ) { final byte [ ] s = str . getBytes ( StandardCharsets . UTF_8 ) ; byte [ ] octets ; if ( s . length > Attribute . MAX_ATTRIBUTE_VALUE_LENGTH ) { octets = new byte [ Attribute . MAX_ATTRIBUTE_LENGTH ] ; octets [ 0 ] = ( byte ) type . getTypeCode ( ) ; octets [ 1 ] = ( byte ) Attribute . MAX_ATTRIBUTE_LENGTH ; System . arraycopy ( s , 0 , octets , 2 , Attribute . MAX_ATTRIBUTE_VALUE_LENGTH ) ; } else { octets = new byte [ s . length + 2 ] ; octets [ 0 ] = ( byte ) type . getTypeCode ( ) ; octets [ 1 ] = ( byte ) ( s . length + 2 ) ; System . arraycopy ( s , 0 , octets , 2 , s . length ) ; } return octets ; }
crafts the on - the - wire octet array conforming to the format of section 3 of rfc 2865 with the value being a string possibly truncated to fit into the maximum of 253 characters allowed for values .
