コード例 #1
0
 public virtual int GetMaxCharCount(int byteCount)
 {
     if (byteCount < 0)
     {
         throw new System.ArgumentOutOfRangeException();
     }
     return((int)(byteCount * PerThreadJavaDecoder.maxCharsPerByte()));
 }
コード例 #2
0
        //
        // Decoder methods
        //

        public virtual int GetChars(byte[] bytes, int byteIndex, int byteCount,
                                    char[] chars, int charIndex)
        {
            if (chars == null || bytes == null)
            {
                throw new System.ArgumentNullException();
            }

            int charLength = chars.Length - charIndex;

            if (byteIndex < 0 || byteCount < 0 || charIndex < 0 ||
                byteIndex + byteCount > bytes.Length || charLength < 0)
            {
                throw new System.ArgumentOutOfRangeException();
            }

            var charBuffer = java.nio.CharBuffer.wrap(chars, charIndex, charLength);
            var byteBuffer = java.nio.ByteBuffer.wrap((sbyte[])(object)bytes, byteIndex, byteCount);

            var decoder = PerThreadJavaDecoder;
            var result  = PerThreadJavaDecoder.decode(byteBuffer, charBuffer, true);

            if (result.isUnderflow())
            {
                result = decoder.flush(charBuffer);
            }

            if (result.isOverflow())
            {
                throw new System.ArgumentException();
            }
            if (!result.isUnderflow())
            {
                throw new System.InvalidOperationException("Decoder exception " + result);
            }

            return(charBuffer.position());
        }