Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / FileStreamResult.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc {\r
14     using System;\r
15     using System.IO;\r
16     using System.Web;\r
17 \r
18     public class FileStreamResult : FileResult {\r
19 \r
20         // default buffer size as defined in BufferedStream type\r
21         private const int _bufferSize = 0x1000;\r
22 \r
23         public FileStreamResult(Stream fileStream, string contentType)\r
24             : base(contentType) {\r
25             if (fileStream == null) {\r
26                 throw new ArgumentNullException("fileStream");\r
27             }\r
28 \r
29             FileStream = fileStream;\r
30         }\r
31 \r
32         public Stream FileStream {\r
33             get;\r
34             private set;\r
35         }\r
36 \r
37         protected override void WriteFile(HttpResponseBase response) {\r
38             // grab chunks of data and write to the output stream\r
39             Stream outputStream = response.OutputStream;\r
40             using (FileStream) {\r
41                 byte[] buffer = new byte[_bufferSize];\r
42 \r
43                 while (true) {\r
44                     int bytesRead = FileStream.Read(buffer, 0, _bufferSize);\r
45                     if (bytesRead == 0) {\r
46                         // no more data\r
47                         break;\r
48                     }\r
49 \r
50                     outputStream.Write(buffer, 0, bytesRead);\r
51                 }\r
52             }\r
53         }\r
54 \r
55     }\r
56 }\r