code: @Override
    protected CoderResult encodeLoop (final CharBuffer in, final ByteBuffer out)
    {
      while (in.hasRemaining ())
      {
        if (out.remaining () < 4)
          return CoderResult.OVERFLOW;
        final char ch = in.get ();
        if (m_aCharset.canEncodeDirectly (ch))
        {
          _unshift (out, ch);
          out.put ((byte) ch);
        }
        else
          if (!m_bBase64mode && ch == m_nShift)
          {
            out.put (m_nShift);
            out.put (m_nUnshift);
          }
          else
            _encodeBase64 (ch, out);
      }
  
      return CoderResult.UNDERFLOW;
    }
docs: {@inheritDoc}
  <p>
  Note that this method might return <code>CoderResult.OVERFLOW</code>, even
  though there is sufficient space available in the output buffer. This is
  done to force the broken implementation of
  {@link java.nio.charset.CharsetEncoder#encode(CharBuffer)} to call flush
  (the buggy method is <code>final</code>, thus cannot be overridden).
  </p>
  <p>
  However, String.getBytes() fails if CoderResult.OVERFLOW is returned, since
  this assumes it always allocates sufficient bytes (maxBytesPerChar *
  nr_of_chars). Thus, as an extra check, the size of the input buffer is
  compared against the size of the output buffer. A static variable is used
  to indicate if a broken java version is used.
  </p>
  <p>
  It is not possible to directly write the last few bytes, since more bytes
  might be waiting to be encoded then those available in the input buffer.
  </p>
  
  @see <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6221056">
  JDK bug 6221056</a>
  @param in
  The input character buffer
  @param out
  The output byte buffer
  @return A coder-result object describing the reason for termination