code: @Nonnull
    public ByteBuffer getAsNewByteBuffer (@Nonnull final String sSource)
    {
      // Optimized for 1 byte per character strings (ASCII)
      ByteBuffer ret = ByteBuffer.allocate (sSource.length () + BUFFER_EXTRA_BYTES);
  
      while (encode (sSource, ret).isContinue ())
      {
        // need a larger buffer
        // estimate the average bytes per character from the current sample
        final int nCharsConverted = _getCharsConverted ();
        double dBytesPerChar;
        if (nCharsConverted > 0)
        {
          dBytesPerChar = ret.position () / (double) nCharsConverted;
        }
        else
        {
          // charsConverted can be 0 if the initial buffer is smaller than one
          // character
          dBytesPerChar = m_aEncoder.averageBytesPerChar ();
        }
  
        final int nCharsRemaining = sSource.length () - nCharsConverted;
        assert nCharsRemaining > 0;
        final int nBytesRemaining = (int) (nCharsRemaining * dBytesPerChar + 0.5);
  
        final int nPos = ret.position ();
        final ByteBuffer aNewBuffer = ByteBuffer.allocate (ret.position () + nBytesRemaining + BUFFER_EXTRA_BYTES);
        ret.flip ();
        aNewBuffer.put (ret);
        aNewBuffer.position (nPos);
        ret = aNewBuffer;
      }
  
      // Set the buffer for reading and finish
      ret.flip ();
      return ret;
    }
docs: Returns a ByteBuffer containing the encoded version of source. The position
  of the ByteBuffer will be 0, the limit is the length of the string. The
  capacity of the ByteBuffer may be larger than the string.
  
  @param sSource
  Source string
  @return The new byte buffer