Beispiel #1
0
 public override int GetHashCode()
 {
     if (this.byteArray != null)
     {
         return((int)WBXmlStreamHelper.UpdateCrc32(0U, this.byteArray, 0, this.byteArray.Length));
     }
     return(base.GetHashCode());
 }
        internal static int CopyStream(StreamAccessor source, Stream target, int offset, int count, bool needCrc, out uint crc)
        {
            byte[] array = null;
            int    num   = 0;

            crc = 0U;
            if (count == 0)
            {
                return(0);
            }
            if (count < 0)
            {
                count = int.MaxValue;
            }
            try
            {
                array = WBXmlStreamHelper.BytesBufferPool.Acquire();
                if (array == null)
                {
                    throw new InvalidOperationException("buffer should never be null.");
                }
                int num2;
                if (source.CanSeek)
                {
                    source.Seek((long)offset, SeekOrigin.Begin);
                }
                else if (offset > 0)
                {
                    do
                    {
                        num2    = source.Read(array, 0, (offset < array.Length) ? offset : array.Length);
                        offset -= num2;
                    }while (num2 > 0 && offset > 0);
                }
                do
                {
                    num2 = source.Read(array, 0, (count < array.Length) ? count : array.Length);
                    if (num2 != 0)
                    {
                        target.Write(array, 0, num2);
                        if (needCrc)
                        {
                            crc = WBXmlStreamHelper.UpdateCrc32(crc, array, 0, num2);
                        }
                        count -= num2;
                        num   += num2;
                    }
                }while (num2 > 0 && count > 0);
            }
            finally
            {
                if (array != null)
                {
                    WBXmlStreamHelper.BytesBufferPool.Release(array);
                }
            }
            return(num);
        }
Beispiel #3
0
 internal void CopyStream(Stream outputStream)
 {
     if (this.stream == null)
     {
         return;
     }
     if (this.stream.CanSeek)
     {
         this.stream.Seek(0L, SeekOrigin.Begin);
     }
     WBXmlStreamHelper.CopyStream(this.stream, outputStream, (int)this.StreamDataSize);
 }
        internal static int CopyStream(Stream source, Stream target, Encoding encoding, int charCount, bool needCrc, out uint crc)
        {
            crc = 0U;
            byte[] array = null;
            WBXmlStreamHelper.CharArrayBuffer charArrayBuffer = null;
            int num = 0;

            if (charCount == 0)
            {
                return(0);
            }
            if (charCount < 0)
            {
                charCount = int.MaxValue;
            }
            int result;

            try
            {
                array           = WBXmlStreamHelper.BytesBufferPool.Acquire();
                charArrayBuffer = WBXmlStreamHelper.CharsBufferPool.Acquire();
                if (array == null)
                {
                    throw new InvalidOperationException("bytesBuffer should never be null.");
                }
                if (charArrayBuffer == null)
                {
                    throw new InvalidOperationException("charsBuffer should never be null.");
                }
                StreamReader streamReader = new StreamReader(source, encoding);
                do
                {
                    int num2 = (6144 > charCount - num - 1) ? (charCount - num - 1) : 6144;
                    if (num2 == 0)
                    {
                        num2 = 1;
                    }
                    int num3 = streamReader.ReadBlock(charArrayBuffer.Buffer, 0, num2);
                    if (num3 == 0)
                    {
                        break;
                    }
                    if (WBXmlStreamHelper.NeedToHandleSurrogate(charArrayBuffer.Buffer, num2, num3))
                    {
                        int num4 = streamReader.Read();
                        if (num4 != -1)
                        {
                            charArrayBuffer.Buffer[num3] = (char)num4;
                            char c  = charArrayBuffer.Buffer[num3];
                            char c2 = charArrayBuffer.Buffer[num3 - 1];
                            if (!char.IsSurrogatePair(c2, c))
                            {
                                string.Format(CultureInfo.InvariantCulture, "Invalid surrogate chars: first={0}, second={1}", new object[]
                                {
                                    c2,
                                    c
                                });
                            }
                            num3++;
                        }
                    }
                    num += num3;
                    int bytes = encoding.GetBytes(charArrayBuffer.Buffer, 0, num3, array, 0);
                    target.Write(array, 0, bytes);
                    if (needCrc)
                    {
                        crc = WBXmlStreamHelper.UpdateCrc32(crc, array, 0, bytes);
                    }
                }while (num < charCount);
                result = num;
            }
            finally
            {
                if (array != null)
                {
                    WBXmlStreamHelper.BytesBufferPool.Release(array);
                }
                if (charArrayBuffer != null)
                {
                    charArrayBuffer.Clear();
                    WBXmlStreamHelper.CharsBufferPool.Release(charArrayBuffer);
                }
            }
            return(result);
        }
        internal static int CopyStream(StreamAccessor source, Stream target, int offset, int count)
        {
            uint num;

            return(WBXmlStreamHelper.CopyStream(source, target, offset, count, false, out num));
        }
 internal static int CopyStream(StreamAccessor source, Stream target, int byteCount, out uint crc)
 {
     return(WBXmlStreamHelper.CopyStream(source, target, 0, byteCount, true, out crc));
 }
 internal static int CopyStream(StreamAccessor source, Stream target)
 {
     return(WBXmlStreamHelper.CopyStream(source, target, int.MaxValue));
 }