code: public static int encodeInteger(int value, ByteBuffer buf) {
          int pos = buf.position();
          int contentLength = 0;
          do {
              pos--;
              buf.put(pos, (byte) (value & 0xff));
              value >>>= 8;
              contentLength++;
          } while (value != 0);
          buf.position(buf.position() - contentLength);
          int headerLen = DerUtils.encodeIdAndLength(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE, ASN1_INTEGER_TAG_NUM,
                  contentLength, buf);
          return headerLen + contentLength;
      }
docs: Encode an ASN.1 INTEGER.
  
  @param value
  the value to be encoded
  @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