Exemple #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);
        }
Exemple #2
0
            fillInput()
            {
                bool ready = false;

                inBuff.clear();                                 // Prepare for reading.

                if ((eoi_flags & EOI_RDR) == 0)                 // Reached end-of-input?
                {
                    /*
                    ** The Reader class does not directly support
                    ** transfer of data with our input buffer, so
                    ** need to read directly into the underlying
                    ** character array (buffer allocation method
                    ** assures the presence of the array).
                    */
                    int length = rdr.read(inBuff.array());

                    /*
                    ** Check for end-of-input.
                    */
                    if (length < 0)
                    {
                        eoi_flags |= EOI_RDR;
                    }
                    else
                    {
                        /*
                        ** Update buffer with amount transferred.
                        */
                        inBuff.position(inBuff.position() + length);
                        ready = true;
                    }
                }

                inBuff.flip(); // Prepare for writing.
                return(ready);
            }                  // fillInput
Exemple #3
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;
        }