HtmlAgilityPack.HtmlWeb.SaveStream C# (CSharp) Method

SaveStream() private static method

private static SaveStream ( Stream stream, string path, System.DateTime touchDate, int streamBufferSize ) : long
stream Stream
path string
touchDate System.DateTime
streamBufferSize int
return long
        private static long SaveStream(Stream stream, string path, DateTime touchDate, int streamBufferSize)
        {
            FilePreparePath(path);
            FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
            BinaryReader br = null;
            BinaryWriter bw = null;
            long len = 0;
            try
            {
                br = new BinaryReader(stream);
                bw = new BinaryWriter(fs);

                byte[] buffer;
                do
                {
                    buffer = br.ReadBytes(streamBufferSize);
                    len += buffer.Length;
                    if (buffer.Length > 0)
                    {
                        bw.Write(buffer);
                    }
                } while (buffer.Length > 0);
            }
            finally
            {
                if (br != null)
                {
                    br.Close();
                }
                if (bw != null)
                {
                    bw.Flush();
                    bw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
            File.SetLastWriteTime(path, touchDate);
            return len;
        }