Esempio n. 1
0
            fillOutput()
            {
                outBuff.clear();                                        // Prepare for reading.

                if ((eoi_flags & EOI_ENC) == 0)                         // Reached end-of-input?
                {
                    do
                    {
                        /*
                        ** Fill input buffer when empty.
                        */
                        if (!inBuff.hasRemaining() && !fillInput())
                        {
                            /*
                            ** We only want to flush the encoder once,
                            ** and then only with an empty output buffer
                            ** to ensure that there will be room for any
                            ** flushed data.  If anything has been placed
                            ** in the output buffer, the end-of-input
                            ** processing will be done on the next call.
                            */
                            if (outBuff.position() == 0)
                            {
                                encoder.encode(inBuff, outBuff, true);
                                encoder.flush(outBuff);
                                eoi_flags |= EOI_ENC;
                            }
                            break;
                        }

                        /*
                        ** Encode input characters into output bytes.
                        ** Loop to fill input buffer when empty.  Only
                        ** UNDERFLOW or OVERFLOW should be returned
                        ** since the encoder has been set to REPLACE
                        ** or IGNORE other coding errors.
                        */
                    } while(encoder.encode(inBuff,
                                           outBuff, false) == CoderResult.UNDERFLOW);
                }

                /*
                ** Only end-of-input can keep somehting from being
                ** placed in the output buffer.  We may have hit
                ** end-of-input and still placed something in the
                ** output buffer, in which case end-of-input will
                ** be signaled on the next call.
                */
                outBuff.flip(); // Prepare for writing.
                return(outBuff.hasRemaining());
            }                   // fillOutput
Esempio n. 2
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);
        }
Esempio n. 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;
        }