code: public void writeShort(short value) throws IOException {
      if (2 > buf.length - pos) {
        //not enough space remaining
        byte[] arr = new byte[2];
        arr[0] = (byte) value;
        arr[1] = (byte) (value >> 8);
        write(arr, 0, 2);
        return;
      }
  
      buf[pos] = (byte) value;
      buf[pos + 1] = (byte) (value >> 8);
      pos += 2;
    }
docs: Write short value into buffer. flush buffer if too small.
  
  @param value short value
  @throws IOException if socket error occur