예제 #1
0
        public static long write(object nd, FileDescriptor fd, ByteBuffer[] bufs, int offset, int length)
        {
#if FIRST_PASS
            return(0);
#else
            ByteBuffer[] altBufs             = null;
            List <ArraySegment <byte> > list = new List <ArraySegment <byte> >(length);
            for (int i = 0; i < length; i++)
            {
                ByteBuffer bb = bufs[i + offset];
                if (!bb.hasArray())
                {
                    if (altBufs == null)
                    {
                        altBufs = new ByteBuffer[bufs.Length];
                    }
                    ByteBuffer abb = ByteBuffer.allocate(bb.remaining());
                    int        pos = bb.position();
                    abb.put(bb);
                    bb.position(pos);
                    abb.flip();
                    bb = altBufs[i + offset] = abb;
                }
                list.Add(new ArraySegment <byte>(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining()));
            }
            int count;
            try
            {
                count = fd.getSocket().Send(list);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                if (x.ErrorCode == global::java.net.SocketUtil.WSAEWOULDBLOCK)
                {
                    count = 0;
                }
                else
                {
                    throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
                }
            }
            catch (ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
            int total = count;
            for (int i = 0; total > 0 && i < length; i++)
            {
                ByteBuffer bb       = bufs[i + offset];
                int        consumed = Math.Min(total, bb.remaining());
                bb.position(bb.position() + consumed);
                total -= consumed;
            }
            return(count);
#endif
        }
예제 #2
0
        public static short getShortNumeric(java.nio.ByteBuffer buffer, int len)
        {
            String s = "";

            if (null != buffer && buffer.remaining() >= len)
            {
                byte[] dest = new byte[len];
                buffer.get(dest, 0, len);
                s = new String(dest);
            }
            return((short)(0xFFFF & Integer.parseInt(s)));
        }
예제 #3
0
        public static String getString(java.nio.ByteBuffer buffer, int len)
        {
            String s = "";

            if (null != buffer && buffer.remaining() >= len)
            {
                byte[] dest = new byte[len];
                buffer.get(dest, 0, len);
                s = new String(dest).trim();
            }
            return(s);
        }
예제 #4
0
        /// <exception cref="System.IO.IOException"/>
        public int Write(java.nio.ByteBuffer src)
        {
            int available = this.buf.remaining();
            int size      = src.remaining();

            if (available < size)
            {
                throw new System.IO.IOException("backing buffer was not large enough " + this.buf.array().Length.ToString() + ", " + available.ToString() + ", " + size.ToString());
            }
            this.buf.put(src);
            return(size);
        }
예제 #5
0
        /// <exception cref="System.IO.IOException"/>
        public int Read(java.nio.ByteBuffer dst)
        {
            int size = System.Math.Min(dst.remaining(), this.buf.remaining());

            java.nio.ByteBuffer slice = this.buf.slice();
            slice.limit(size);
            dst.buffer = slice.buffer;
            dst.offset = slice.offset;
            dst.limit(size);
            dst.position(size);
            this.buf.position(this.buf.position() + size);
            return(size);
        }
예제 #6
0
        /// <exception cref="System.IO.IOException"/>
        public int Read(java.nio.ByteBuffer dst)
        {
            int numBytes = dst.remaining();

            if (numBytes < this.buf.remaining())
            {
                //# Serve from the current buffer.
                java.nio.ByteBuffer slice = this.buf.slice();
                slice.limit(numBytes);
                dst.put(slice);
                this.buf.position(this.buf.position() + numBytes);
                return(numBytes);
            }
            else
            {
                //# Copy current available into destination.
                int fromFirstBuffer = this.buf.remaining();
                {
                    java.nio.ByteBuffer slice = this.buf.slice();
                    slice.limit(fromFirstBuffer);
                    dst.put(slice);
                }
                numBytes -= fromFirstBuffer;
                if (numBytes <= this.buf.capacity())
                {
                    //# Read the next buffer-full.
                    this.buf.clear();
                    int n = readAtLeast(this.inner, this.buf, numBytes);
                    this.buf.rewind();
                    java.nio.ByteBuffer slice = this.buf.slice();
                    slice.limit(numBytes);
                    dst.put(slice);
                    this.buf.limit(n);
                    this.buf.position(numBytes);
                    return(fromFirstBuffer + numBytes);
                }
                else
                {
                    //# Forward large read to the underlying stream.
                    this.buf.clear();
                    this.buf.limit(0);
                    return(fromFirstBuffer + readAtLeast(this.inner, dst, numBytes));
                }
            }
        }
예제 #7
0
        /// <exception cref="System.IO.IOException"/>
        public int Write(java.nio.ByteBuffer src)
        {
            int available = this.buf.remaining();
            int size      = src.remaining();

            if (size <= available)
            {
                this.buf.put(src);
            }
            else if (size <= this.buf.capacity())
            {
                //# Too much for this buffer, but not a full buffer's worth,
                //# so we'll go ahead and copy.
                java.nio.ByteBuffer slice = src.slice();
                slice.limit(available);
                this.buf.put(slice);
                this.buf.rewind();
                while (this.buf.hasRemaining())
                {
                    this.inner.Write(this.buf);
                }
                this.buf.rewind();
                src.position(src.position() + available);
                this.buf.put(src);
            }
            else
            {
                //# Writing so much data that we might as well write
                //# directly to avoid a copy.
                int pos = this.buf.position();
                this.buf.rewind();
                java.nio.ByteBuffer slice = this.buf.slice();
                slice.limit(pos);
                while (slice.hasRemaining())
                {
                    this.inner.Write(slice);
                }
                while (src.hasRemaining())
                {
                    this.inner.Write(src);
                }
            }
            return(size);
        }
예제 #8
0
        /// <summary>This is a facade method for the decoding operation.</summary>
        /// <remarks>
        /// This is a facade method for the decoding operation.
        /// <p>
        /// This method decodes the remaining byte sequence of the given byte buffer
        /// into a new character buffer. This method performs a complete decoding
        /// operation, resets at first, then decodes, and flushes at last.
        /// <p>
        /// This method should not be invoked while another
        /// <code>decode</code>
        /// operation
        /// is ongoing.
        /// </remarks>
        /// <param name="in">the input buffer.</param>
        /// <returns>
        /// a new <code>CharBuffer</code> containing the the characters
        /// produced by this decoding operation. The buffer's limit will be
        /// the position of the last character in the buffer, and the
        /// position will be zero.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">if another decoding operation is ongoing.
        ///     </exception>
        /// <exception cref="MalformedInputException">
        /// if an illegal input byte sequence for this charset was
        /// encountered, and the action for malformed error is
        /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
        /// </exception>
        /// <exception cref="UnmappableCharacterException">
        /// if a legal but unmappable input byte sequence for this
        /// charset was encountered, and the action for unmappable
        /// character error is
        /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
        /// .
        /// Unmappable means the byte sequence at the input buffer's
        /// current position cannot be mapped to a Unicode character
        /// sequence.
        /// </exception>
        /// <exception cref="CharacterCodingException">if another exception happened during the decode operation.
        ///     </exception>
        /// <exception cref="java.nio.charset.CharacterCodingException"></exception>
        public java.nio.CharBuffer decode(java.nio.ByteBuffer @in)
        {
            reset();
            int length = (int)(@in.remaining() * _averageCharsPerByte);

            java.nio.CharBuffer          output = java.nio.CharBuffer.allocate(length);
            java.nio.charset.CoderResult result = null;
            while (true)
            {
                result = decode(@in, output, false);
                checkCoderResult(result);
                if (result.isUnderflow())
                {
                    break;
                }
                else
                {
                    if (result.isOverflow())
                    {
                        output = allocateMore(output);
                    }
                }
            }
            result = decode(@in, output, true);
            checkCoderResult(result);
            while (true)
            {
                result = flush(output);
                checkCoderResult(result);
                if (result.isOverflow())
                {
                    output = allocateMore(output);
                }
                else
                {
                    break;
                }
            }
            output.flip();
            status = FLUSH;
            return(output);
        }
예제 #9
0
        public virtual java.nio.ByteBuffer put(java.nio.ByteBuffer src)
        {
            if (src == this)
            {
                throw new System.ArgumentException("src == this");
            }
            int srcByteCount = src.remaining();

            if (srcByteCount > remaining())
            {
                throw new java.nio.BufferOverflowException();
            }
            if (src.isDirect())
            {
                throw new System.InvalidOperationException();
            }
            byte[] srcObject = java.nio.NioUtils.unsafeArray(src);
            int    srcOffset = src.position();

            if (!src.isDirect())
            {
                srcOffset += java.nio.NioUtils.unsafeArrayOffset(src);
            }
            java.nio.ByteBuffer dst = this;
            if (dst.isDirect())
            {
                throw new System.InvalidOperationException();
            }
            byte[] dstObject = java.nio.NioUtils.unsafeArray(dst);
            int    dstOffset = dst.position();

            if (!dst.isDirect())
            {
                dstOffset += java.nio.NioUtils.unsafeArrayOffset(dst);
            }
            System.Array.Copy(srcObject, srcOffset, dstObject, dstOffset, srcByteCount);
            src.position(src.limit());
            dst.position(dst.position() + srcByteCount);
            return(this);
        }
예제 #10
0
        public static String getBitString(java.nio.ByteBuffer buffer, int lenBits)
        {
            String s   = "";
            int    len = (int)Math.Ceiling(lenBits / (double)Byte.SIZE);

            if (null != buffer && buffer.remaining() >= len)
            {
                byte[] dest = new byte[len];
                buffer.get(dest, 0, len);

                char[] bits = new char[lenBits];
                for (int i = 0; i < lenBits; i++)
                {
                    int mask = 0x1 << (Byte.SIZE - (i % Byte.SIZE) - 1);
                    // U+0030 : unicode zero
                    // U+0031 : unicode one
                    bits[i] = (mask & dest[i / Byte.SIZE]) == 0 ? '\u0030' : '\u0031';
                }
                s = new String(bits);
            }
            return(s);
        }
예제 #11
0
        /// <exception cref="System.IO.IOException"/>
        public int Read(java.nio.ByteBuffer outBuf)
        {
            if (outBuf.buffer == null)
            {
                outBuf.buffer = new byte[outBuf.remaining()];
            }
            int len = outBuf.remaining();

            if (len == 0)
            {
                return(0);
            }
            if (len % 8 != 0)
            {
                throw new System.Exception("PackedInputStream reads must be word-aligned");
            }
            int outPtr = outBuf.position();
            int outEnd = outPtr + len;

            java.nio.ByteBuffer inBuf = this.inner.GetReadBuffer();
            while (true)
            {
                byte tag = 0;
                if (inBuf.remaining() < 10)
                {
                    if (outBuf.remaining() == 0)
                    {
                        return(len);
                    }
                    if (inBuf.remaining() == 0)
                    {
                        inBuf = this.inner.GetReadBuffer();
                        continue;
                    }
                    //# We have at least 1, but not 10, bytes available. We need to read
                    //# slowly, doing a bounds check on each byte.
                    tag = inBuf.get();
                    for (int i = 0; i < 8; ++i)
                    {
                        if ((tag & (1 << i)) != 0)
                        {
                            if (inBuf.remaining() == 0)
                            {
                                inBuf = this.inner.GetReadBuffer();
                            }
                            outBuf.put(inBuf.get());
                        }
                        else
                        {
                            outBuf.put((byte)0);
                        }
                    }
                    if (inBuf.remaining() == 0 && (tag == 0 || tag == 0xff))
                    {
                        inBuf = this.inner.GetReadBuffer();
                    }
                }
                else
                {
                    tag = inBuf.get();
                    for (int n = 0; n < 8; ++n)
                    {
                        bool isNonzero = (tag & (1 << n)) != 0;
                        outBuf.put(unchecked ((byte)(inBuf.get() & (isNonzero? -1 : 0))));
                        inBuf.position(inBuf.position() + (isNonzero? 0 : -1));
                    }
                }
                if (tag == 0)
                {
                    if (inBuf.remaining() == 0)
                    {
                        throw new System.Exception("Should always have non-empty buffer here.");
                    }
                    int runLength = (unchecked ((int)(0xff)) & (int)inBuf.get()) * 8;
                    if (runLength > outEnd - outPtr)
                    {
                        throw new System.Exception("Packed input did not end cleanly on a segment boundary");
                    }
                    for (int i = 0; i < runLength; ++i)
                    {
                        outBuf.put((byte)0);
                    }
                }
                else if (tag == 0xff)
                {
                    int runLength = (unchecked ((int)(0xff)) & (int)inBuf.get()) * 8;
                    if (inBuf.remaining() >= runLength)
                    {
                        //# Fast path.
                        java.nio.ByteBuffer slice = inBuf.slice();
                        slice.limit(runLength);
                        outBuf.put(slice);
                        inBuf.position(inBuf.position() + runLength);
                    }
                    else
                    {
                        //# Copy over the first buffer, then do one big read for the rest.
                        runLength -= inBuf.remaining();
                        outBuf.put(inBuf);
                        java.nio.ByteBuffer slice = outBuf.slice();
                        slice.limit(runLength);
                        this.inner.Read(slice);
                        outBuf.position(outBuf.position() + runLength);
                        if (outBuf.remaining() == 0)
                        {
                            return(len);
                        }
                        inBuf = this.inner.GetReadBuffer();
                        continue;
                    }
                }
                if (outBuf.remaining() == 0)
                {
                    return(len);
                }
            }
        }
예제 #12
0
 /// <summary>
 /// Encodes characters starting at the current position of the given input
 /// buffer, and writes the equivalent byte sequence into the given output
 /// buffer from its current position.
 /// </summary>
 /// <remarks>
 /// Encodes characters starting at the current position of the given input
 /// buffer, and writes the equivalent byte sequence into the given output
 /// buffer from its current position.
 /// <p>
 /// The buffers' position will be changed with the reading and writing
 /// operation, but their limits and marks will be kept intact.
 /// <p>
 /// A <code>CoderResult</code> instance will be returned according to
 /// following rules:
 /// <ul>
 /// <li>A
 /// <see cref="CoderResult.malformedForLength(int)">malformed input</see>
 /// result
 /// indicates that some malformed input error was encountered, and the
 /// erroneous characters start at the input buffer's position and their
 /// number can be got by result's
 /// <see cref="CoderResult.length()">length</see>
 /// . This
 /// kind of result can be returned only if the malformed action is
 /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
 /// .</li>
 /// <li>
 /// <see cref="CoderResult.UNDERFLOW">CoderResult.UNDERFLOW</see>
 /// indicates that
 /// as many characters as possible in the input buffer have been encoded. If
 /// there is no further input and no characters left in the input buffer then
 /// this task is complete. If this is not the case then the client should
 /// call this method again supplying some more input characters.</li>
 /// <li>
 /// <see cref="CoderResult.OVERFLOW">CoderResult.OVERFLOW</see>
 /// indicates that the
 /// output buffer has been filled, while there are still some characters
 /// remaining in the input buffer. This method should be invoked again with a
 /// non-full output buffer.</li>
 /// <li>A
 /// <see cref="CoderResult.unmappableForLength(int)">unmappable character</see>
 /// result indicates that some unmappable character error was encountered,
 /// and the erroneous characters start at the input buffer's position and
 /// their number can be got by result's
 /// <see cref="CoderResult.length()">length</see>
 /// .
 /// This kind of result can be returned only on
 /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
 /// .</li>
 /// </ul>
 /// <p>
 /// The <code>endOfInput</code> parameter indicates if the invoker can
 /// provider further input. This parameter is true if and only if the
 /// characters in the current input buffer are all inputs for this encoding
 /// operation. Note that it is common and won't cause an error if the invoker
 /// sets false and then has no more input available, while it may cause an
 /// error if the invoker always sets true in several consecutive invocations.
 /// This would make the remaining input to be treated as malformed input.
 /// input.
 /// <p>
 /// This method invokes the
 /// <see cref="encodeLoop(java.nio.CharBuffer, java.nio.ByteBuffer)">encodeLoop</see>
 /// method to
 /// implement the basic encode logic for a specific charset.
 /// </remarks>
 /// <param name="in">the input buffer.</param>
 /// <param name="out">the output buffer.</param>
 /// <param name="endOfInput">true if all the input characters have been provided.</param>
 /// <returns>a <code>CoderResult</code> instance indicating the result.</returns>
 /// <exception cref="System.InvalidOperationException">
 /// if the encoding operation has already started or no more
 /// input is needed in this encoding process.
 /// </exception>
 /// <exception cref="CoderMalfunctionError">
 /// If the
 /// <see cref="encodeLoop(java.nio.CharBuffer, java.nio.ByteBuffer)">encodeLoop</see>
 /// method threw an <code>BufferUnderflowException</code> or
 /// <code>BufferUnderflowException</code>.
 /// </exception>
 public java.nio.charset.CoderResult encode(java.nio.CharBuffer @in, java.nio.ByteBuffer
                                            @out, bool endOfInput)
 {
     // If the previous step is encode(CharBuffer), then no more input is needed
     // thus endOfInput should not be false
     if (status == READY && finished && !endOfInput)
     {
         throw new System.InvalidOperationException();
     }
     if ((status == FLUSH) || (!endOfInput && status == END))
     {
         throw new System.InvalidOperationException();
     }
     java.nio.charset.CoderResult result;
     while (true)
     {
         try
         {
             result = encodeLoop(@in, @out);
         }
         catch (java.nio.BufferOverflowException e)
         {
             throw new java.nio.charset.CoderMalfunctionError(e);
         }
         catch (java.nio.BufferUnderflowException e)
         {
             throw new java.nio.charset.CoderMalfunctionError(e);
         }
         if (result == java.nio.charset.CoderResult.UNDERFLOW)
         {
             status = endOfInput ? END : ONGOING;
             if (endOfInput)
             {
                 int remaining = @in.remaining();
                 if (remaining > 0)
                 {
                     result = java.nio.charset.CoderResult.malformedForLength(remaining);
                 }
                 else
                 {
                     return(result);
                 }
             }
             else
             {
                 return(result);
             }
         }
         else
         {
             if (result == java.nio.charset.CoderResult.OVERFLOW)
             {
                 status = endOfInput ? END : ONGOING;
                 return(result);
             }
         }
         java.nio.charset.CodingErrorAction action = _malformedInputAction;
         if (result.isUnmappable())
         {
             action = _unmappableCharacterAction;
         }
         // If the action is IGNORE or REPLACE, we should continue
         // encoding.
         if (action == java.nio.charset.CodingErrorAction.REPLACE)
         {
             if (@out.remaining() < replacementBytes.Length)
             {
                 return(java.nio.charset.CoderResult.OVERFLOW);
             }
             @out.put(replacementBytes);
         }
         else
         {
             if (action != java.nio.charset.CodingErrorAction.IGNORE)
             {
                 return(result);
             }
         }
         @in.position(@in.position() + result.length());
     }
 }
예제 #13
0
        /// <exception cref="System.IO.IOException"/>
        public int Write(java.nio.ByteBuffer inBuf)
        {
            int length = inBuf.remaining();

            java.nio.ByteBuffer @out       = this.inner.GetWriteBuffer();
            java.nio.ByteBuffer slowBuffer = java.nio.ByteBuffer.allocate(20);
            int inPtr = inBuf.position();
            int inEnd = inPtr + length;

            while (inPtr < inEnd)
            {
                if (@out.remaining() < 10)
                {
                    //# Oops, we're out of space. We need at least 10
                    //# bytes for the fast path, since we don't
                    //# bounds-check on every byte.
                    if (@out == slowBuffer)
                    {
                        int oldLimit = @out.limit();
                        @out.limit(@out.position());
                        @out.rewind();
                        this.inner.Write(@out);
                        @out.limit(oldLimit);
                    }
                    @out = slowBuffer;
                    @out.rewind();
                }
                int tagPos = @out.position();
                @out.position(tagPos + 1);
                byte curByte;
                curByte = inBuf.get(inPtr);
                byte bit0 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0);
                @out.put(curByte);
                @out.position(@out.position() + bit0 - 1);
                inPtr  += 1;
                curByte = inBuf.get(inPtr);
                byte bit1 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0);
                @out.put(curByte);
                @out.position(@out.position() + bit1 - 1);
                inPtr  += 1;
                curByte = inBuf.get(inPtr);
                byte bit2 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0);
                @out.put(curByte);
                @out.position(@out.position() + bit2 - 1);
                inPtr  += 1;
                curByte = inBuf.get(inPtr);
                byte bit3 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0);
                @out.put(curByte);
                @out.position(@out.position() + bit3 - 1);
                inPtr  += 1;
                curByte = inBuf.get(inPtr);
                byte bit4 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0);
                @out.put(curByte);
                @out.position(@out.position() + bit4 - 1);
                inPtr  += 1;
                curByte = inBuf.get(inPtr);
                byte bit5 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0);
                @out.put(curByte);
                @out.position(@out.position() + bit5 - 1);
                inPtr  += 1;
                curByte = inBuf.get(inPtr);
                byte bit6 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0);
                @out.put(curByte);
                @out.position(@out.position() + bit6 - 1);
                inPtr  += 1;
                curByte = inBuf.get(inPtr);
                byte bit7 = (curByte != 0)? unchecked ((byte)1) : unchecked ((byte)0);
                @out.put(curByte);
                @out.position(@out.position() + bit7 - 1);
                inPtr += 1;
                byte tag = unchecked ((byte)((bit0 << 0) | (bit1 << 1) | (bit2 << 2) | (bit3 << 3)
                                             | (bit4 << 4) | (bit5 << 5) | (bit6 << 6) | (bit7 << 7)));
                @out.put(tagPos, tag);
                if (tag == 0)
                {
                    //# An all-zero word is followed by a count of
                    //# consecutive zero words (not including the first
                    //# one).
                    int runStart = inPtr;
                    int limit    = inEnd;
                    if (limit - inPtr > 255 * 8)
                    {
                        limit = inPtr + 255 * 8;
                    }
                    while (inPtr < limit && inBuf.getLong(inPtr) == 0)
                    {
                        inPtr += 8;
                    }
                    @out.put(unchecked ((byte)((inPtr - runStart) / 8)));
                }
                else if (tag == unchecked ((byte)unchecked ((int)(0xff))))
                {
                    //# An all-nonzero word is followed by a count of
                    //# consecutive uncompressed words, followed by the
                    //# uncompressed words themselves.
                    //# Count the number of consecutive words in the input
                    //# which have no more than a single zero-byte. We look
                    //# for at least two zeros because that's the point
                    //# where our compression scheme becomes a net win.
                    int runStart = inPtr;
                    int limit    = inEnd;
                    if (limit - inPtr > 255 * 8)
                    {
                        limit = inPtr + 255 * 8;
                    }
                    while (inPtr < limit)
                    {
                        byte c = 0;
                        for (int ii = 0; ii < 8; ++ii)
                        {
                            c     += (inBuf.get(inPtr) == 0 ? (byte)1 : (byte)0);
                            inPtr += 1;
                        }
                        if (c >= 2)
                        {
                            //# Un-read the word with multiple zeros, since
                            //# we'll want to compress that one.
                            inPtr -= 8;
                            break;
                        }
                    }
                    int count = inPtr - runStart;
                    @out.put(unchecked ((byte)(count / 8)));
                    if (count <= @out.remaining())
                    {
                        //# There's enough space to memcpy.
                        inBuf.position(runStart);
                        java.nio.ByteBuffer slice = inBuf.slice();
                        slice.limit(count);
                        @out.put(slice);
                    }
                    else
                    {
                        //# Input overruns the output buffer. We'll give it
                        //# to the output stream in one chunk and let it
                        //# decide what to do.
                        if (@out == slowBuffer)
                        {
                            int oldLimit = @out.limit();
                            @out.limit(@out.position());
                            @out.rewind();
                            this.inner.Write(@out);
                            @out.limit(oldLimit);
                        }
                        inBuf.position(runStart);
                        java.nio.ByteBuffer slice = inBuf.slice();
                        slice.limit(count);
                        while (slice.hasRemaining())
                        {
                            this.inner.Write(slice);
                        }
                        @out = this.inner.GetWriteBuffer();
                    }
                }
            }
            if (@out == slowBuffer)
            {
                @out.limit(@out.position());
                @out.rewind();
                this.inner.Write(@out);
            }
            inBuf.position(inPtr);
            return(length);
        }
예제 #14
0
 /// <summary>
 /// Decodes bytes starting at the current position of the given input buffer,
 /// and writes the equivalent character sequence into the given output buffer
 /// from its current position.
 /// </summary>
 /// <remarks>
 /// Decodes bytes starting at the current position of the given input buffer,
 /// and writes the equivalent character sequence into the given output buffer
 /// from its current position.
 /// <p>
 /// The buffers' position will be changed with the reading and writing
 /// operation, but their limits and marks will be kept intact.
 /// <p>
 /// A <code>CoderResult</code> instance will be returned according to
 /// following rules:
 /// <ul>
 /// <li>
 /// <see cref="CoderResult.OVERFLOW">CoderResult.OVERFLOW</see>
 /// indicates that
 /// even though not all of the input has been processed, the buffer the
 /// output is being written to has reached its capacity. In the event of this
 /// code being returned this method should be called once more with an
 /// <code>out</code> argument that has not already been filled.</li>
 /// <li>
 /// <see cref="CoderResult.UNDERFLOW">CoderResult.UNDERFLOW</see>
 /// indicates that
 /// as many bytes as possible in the input buffer have been decoded. If there
 /// is no further input and no remaining bytes in the input buffer then this
 /// operation may be regarded as complete. Otherwise, this method should be
 /// called once more with additional input.</li>
 /// <li>A
 /// <see cref="CoderResult.malformedForLength(int)">malformed input</see>
 /// result
 /// indicates that some malformed input error has been encountered, and the
 /// erroneous bytes start at the input buffer's position and their number can
 /// be got by result's
 /// <see cref="CoderResult.length()">length</see>
 /// . This kind of
 /// result can be returned only if the malformed action is
 /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
 /// . </li>
 /// <li>A
 /// <see cref="CoderResult.unmappableForLength(int)">unmappable character</see>
 /// result indicates that some unmappable character error has been
 /// encountered, and the erroneous bytes start at the input buffer's position
 /// and their number can be got by result's
 /// <see cref="CoderResult.length()">length</see>
 /// . This kind of result can be returned
 /// only if the unmappable character action is
 /// <see cref="CodingErrorAction.REPORT">CodingErrorAction.REPORT</see>
 /// . </li>
 /// </ul>
 /// <p>
 /// The <code>endOfInput</code> parameter indicates that the invoker cannot
 /// provide further input. This parameter is true if and only if the bytes in
 /// current input buffer are all inputs for this decoding operation. Note
 /// that it is common and won't cause an error if the invoker sets false and
 /// then can't provide more input, while it may cause an error if the invoker
 /// always sets true in several consecutive invocations. This would make the
 /// remaining input to be treated as malformed input.
 /// <p>
 /// This method invokes the
 /// <see cref="decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer)">decodeLoop</see>
 /// method to
 /// implement the basic decode logic for a specific charset.
 /// </remarks>
 /// <param name="in">the input buffer.</param>
 /// <param name="out">the output buffer.</param>
 /// <param name="endOfInput">true if all the input characters have been provided.</param>
 /// <returns>
 /// a <code>CoderResult</code> instance which indicates the reason
 /// of termination.
 /// </returns>
 /// <exception cref="System.InvalidOperationException">
 /// if decoding has started or no more input is needed in this
 /// decoding progress.
 /// </exception>
 /// <exception cref="CoderMalfunctionError">
 /// if the
 /// <see cref="decodeLoop(java.nio.ByteBuffer, java.nio.CharBuffer)">decodeLoop</see>
 /// method threw an <code>BufferUnderflowException</code> or
 /// <code>BufferOverflowException</code>.
 /// </exception>
 public java.nio.charset.CoderResult decode(java.nio.ByteBuffer @in, java.nio.CharBuffer
                                            @out, bool endOfInput)
 {
     if ((status == FLUSH) || (!endOfInput && status == END))
     {
         throw new System.InvalidOperationException();
     }
     java.nio.charset.CoderResult result = null;
     // begin to decode
     while (true)
     {
         java.nio.charset.CodingErrorAction action = null;
         try
         {
             result = decodeLoop(@in, @out);
         }
         catch (java.nio.BufferOverflowException ex)
         {
             // unexpected exception
             throw new java.nio.charset.CoderMalfunctionError(ex);
         }
         catch (java.nio.BufferUnderflowException ex)
         {
             // unexpected exception
             throw new java.nio.charset.CoderMalfunctionError(ex);
         }
         if (result.isUnderflow())
         {
             int remaining = @in.remaining();
             status = endOfInput ? END : ONGOING;
             if (endOfInput && remaining > 0)
             {
                 result = java.nio.charset.CoderResult.malformedForLength(remaining);
             }
             else
             {
                 return(result);
             }
         }
         if (result.isOverflow())
         {
             return(result);
         }
         // set coding error handle action
         action = _malformedInputAction;
         if (result.isUnmappable())
         {
             action = _unmappableCharacterAction;
         }
         // If the action is IGNORE or REPLACE, we should continue decoding.
         if (action == java.nio.charset.CodingErrorAction.REPLACE)
         {
             if (@out.remaining() < replacementChars.Length)
             {
                 return(java.nio.charset.CoderResult.OVERFLOW);
             }
             @out.put(replacementChars);
         }
         else
         {
             if (action != java.nio.charset.CodingErrorAction.IGNORE)
             {
                 return(result);
             }
         }
         @in.position(@in.position() + result.length());
     }
 }