示例#1
0
        public CoderResult encode(
			CharBuffer inBuff, ByteBuffer outBuff, bool endOfInput )
        {
            int oldPosition;
            byte[] ba = new byte[32];
            char[] ca = new char[1];

            while(inBuff.hasRemaining())
            {
                oldPosition = inBuff.position();  // save the input position
                ca[1] = inBuff.get();             // get the next character
                int count = encoding.GetBytes(ca, 0, 1, ba, 0);
                if (count > outBuff.remaining())
                {
                    inBuff.position(oldPosition);
                    return CoderResult.OVERFLOW;
                }
                outBuff.put(ba, 0, count);  // move the bytes into ByteBuffer
            }
            return CoderResult.UNDERFLOW;
        }