System.Xml.XmlDictionaryReader.ReadContentAsBytes C# (CSharp) Méthode

ReadContentAsBytes() private méthode

private ReadContentAsBytes ( bool base64, int maxByteArrayContentLength ) : byte[]
base64 bool
maxByteArrayContentLength int
Résultat byte[]
        private byte[] ReadContentAsBytes(bool base64, int maxByteArrayContentLength)
        {
            byte[][] buffers = new byte[32][];
            byte[] buffer;
            // Its best to read in buffers that are a multiple of 3 so we don't break base64 boundaries when converting text
            int count = 384;
            int bufferCount = 0;
            int totalRead = 0;
            while (true)
            {
                buffer = new byte[count];
                buffers[bufferCount++] = buffer;
                int read = 0;
                while (read < buffer.Length)
                {
                    int actual;
                    if (base64)
                        actual = ReadContentAsBase64(buffer, read, buffer.Length - read);
                    else
                        actual = ReadContentAsBinHex(buffer, read, buffer.Length - read);
                    if (actual == 0)
                        break;
                    read += actual;
                }
                totalRead += read;
                if (read < buffer.Length)
                    break;
                count = count * 2;
            }
            buffer = new byte[totalRead];
            int offset = 0;
            for (int i = 0; i < bufferCount - 1; i++)
            {
                Buffer.BlockCopy(buffers[i], 0, buffer, offset, buffers[i].Length);
                offset += buffers[i].Length;
            }
            Buffer.BlockCopy(buffers[bufferCount - 1], 0, buffer, offset, totalRead - offset);
            return buffer;
        }