code: public static int encodeOctetString(short[] octets, ByteBuffer buf) {
          if (octets == null) {
              octets = new short[0];
          }
          int pos = buf.position();
          for (int i = octets.length - 1; i >= 0; i--) {
              pos--;
              buf.put(pos, (byte) octets[i]);
          }
          buf.position(buf.position() - octets.length);
          int headerLength = DerUtils.encodeIdAndLength(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE,
                  ASN1_OCTET_STRING_TAG_NUM, octets.length, buf);
          return headerLength + octets.length;
      }
docs: Encode an ASN.1 OCTET STRING.
  
  @param octets
  the octets
  @param buf
  the buffer with space to the left of current position where the value will be encoded
  @return the length of the encoded data