private static bool InitializeResponseData()

in AdlsDotNetSDK/WebTransport.cs [349:392]


        private static bool InitializeResponseData(HttpWebResponse webResponse, ref ByteBuffer responseData, bool isResponseError = false)
        {
            string encoding = webResponse.Headers["Transfer-Encoding"];
            if (!string.IsNullOrEmpty(encoding) && encoding.Equals("chunked"))
            {
                // If the error response is from our FE, then it wont be chunked. If the error is from IIS
                // then it may be chunked. So assign a default size of the error response. Even if the remote error 
                // is not contained in that buffer size, its fine.
                if (isResponseError)
                {
                    responseData.Data = new byte[ErrorResponseDefaultLength];
                    responseData.Count = ErrorResponseDefaultLength;
                    responseData.Offset = 0;
                }
                //If it is chunked responseData should be instantiated and responseDataLength should be greater than 0, because we dont know the content length
                if (responseData.Data == null)
                {
                    throw new ArgumentNullException(nameof(responseData.Data));
                }
                if (responseData.Offset >= responseData.Data.Length || responseData.Offset < 0 ||
                    responseData.Count + responseData.Offset > responseData.Data.Length)
                {
                    throw new ArgumentOutOfRangeException(nameof(responseData.Offset));
                }
            }
            else
            {
                //Initialize the response based on content length property
                if (responseData.Data == null) //For OPEN operation the data might not be chunked
                {
                    if (webResponse.ContentLength > 0)
                    {
                        responseData.Data = new byte[webResponse.ContentLength];
                        responseData.Offset = 0;
                        responseData.Count = (int)webResponse.ContentLength;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return true;
        }