2002-10-25 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 25 Oct 2002 01:46:05 +0000 (01:46 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 25 Oct 2002 01:46:05 +0000 (01:46 -0000)
* HttpResponse.cs: implemented WriteFile methods.
* MimeTypes.cs: removed duplicated entries.

svn path=/trunk/mcs/; revision=8537

mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpResponse.cs
mcs/class/System.Web/System.Web/MimeTypes.cs

index 9d94d7d685ffd473b20ac9f1f7a7550c4fe31f05..f8d23aa98032b6b725561704176f16ecc0e06c25 100644 (file)
@@ -1,3 +1,8 @@
+2002-10-25  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * HttpResponse.cs: implemented WriteFile methods.
+       * MimeTypes.cs: removed duplicated entries.
+
 2002-10-24  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * HttpResponse.cs: don't throw exception in a couple of
index 77067bdf1237dc5e791af11fb343cf4ad74b6e8a..9b34316badd9303b262e6829a662ff2a3aa692d9 100644 (file)
@@ -1,8 +1,11 @@
 // 
 // System.Web.HttpResponse
 //
-// Author:
-//   Patrik Torstensson (Patrik.Torstensson@labs2.com)
+// Authors:
+//     Patrik Torstensson (Patrik.Torstensson@labs2.com)
+//     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (c) 2002 Ximian, Inc. (http://www.ximian.com)
 //
 using System;
 using System.Collections;
@@ -437,7 +440,8 @@ namespace System.Web
                        }
                }
 
-               public string StatusDescription {
+               public string StatusDescription
+               {
                        get {
                                if (null == _sStatusDescription)
                                        _sStatusDescription =
@@ -756,7 +760,7 @@ namespace System.Web
 
                public void Write (char [] buffer, int index, int count)
                {
-                       _TextWriter.Write(buffer, index, count);
+                       _TextWriter.Write (buffer, index, count);
                }
 
                [MonoTODO()]
@@ -771,26 +775,71 @@ namespace System.Web
                        throw new NotImplementedException ();
                }
 
+               private void WriteFromStream (Stream stream, long offset, long length, long bufsize)
+               {
+                       if (offset < 0 || length <= 0)
+                               return;
+                       
+                       long stLength = stream.Length;
+                       if (offset + length > stLength)
+                               length = stLength - offset;
+
+                       if (offset > 0)
+                               stream.Seek (offset, SeekOrigin.Begin);
+
+                       byte [] fileContent = new byte [bufsize];
+                       int count = (int) Math.Min (Int32.MaxValue, bufsize);
+                       while (length > 0 && (count = stream.Read (fileContent, 0, count)) != 0) {
+                               _Writer.WriteBytes (fileContent, 0, count);
+                               length -= count;
+                               count = (int) Math.Min (length, fileContent.Length);
+                       }
+               }
+
                public void WriteFile (string filename)
                {
                        WriteFile (filename, false);
                }
 
-               [MonoTODO()]
                public void WriteFile (string filename, bool readIntoMemory)
                {
-                       throw new NotImplementedException ();
+                       FileStream fs = null;
+                       try {
+                               fs = File.OpenRead (filename);
+                               long size = fs.Length;
+                               if (readIntoMemory) {
+                                       WriteFromStream (fs, 0, size, size);
+                               } else {
+                                       WriteFromStream (fs, 0, size, 8192);
+                               }
+                       } finally {
+                               if (fs != null)
+                                       fs.Close ();
+                       }
                }
 
-               [MonoTODO()]
                public void WriteFile (string filename, long offset, long size)
                {
-                       throw new NotImplementedException ();
+                       FileStream fs = null;
+                       try {
+                               fs = File.OpenRead (filename);
+                               WriteFromStream (fs, offset, size, 8192);
+                       } finally {
+                               if (fs != null)
+                                       fs.Close ();
+                       }
                }
 
-               [MonoTODO("Should we support fileHandle ptrs?")]
                public void WriteFile (IntPtr fileHandle, long offset, long size)
                {
+                       FileStream fs = null;
+                       try {
+                               fs = new FileStream (fileHandle, FileAccess.Read);
+                               WriteFromStream (fs, offset, size, 8192);
+                       } finally {
+                               if (fs != null)
+                                       fs.Close ();
+                       }
                }   
 
                [MonoTODO()]
index 83136d9a6e05558428f754c5f58b9bf9a35d45d1..ff267d853c11e5d0e1da5483dac557df23be13d2 100644 (file)
@@ -63,7 +63,6 @@ namespace System.Web
                        mimeTypes.Add ("cco", "application/x-cocoa");
                        mimeTypes.Add ("cdf", "application/cdf");
                        mimeTypes.Add ("cer", "application/pkix-cert");
-                       mimeTypes.Add ("cer", "application/x-x509-ca-cert");
                        mimeTypes.Add ("cha", "application/x-chat");
                        mimeTypes.Add ("chat", "application/x-chat");
                        mimeTypes.Add ("class", "application/java");
@@ -73,7 +72,6 @@ namespace System.Web
                        mimeTypes.Add ("cpt", "application/x-cpt");
                        mimeTypes.Add ("crl", "application/pkix-crl");
                        mimeTypes.Add ("crt", "application/pkix-cert");
-                       mimeTypes.Add ("crt", "application/x-x509-ca-cert");
                        mimeTypes.Add ("csh", "application/x-csh");
                        mimeTypes.Add ("css", "text/css");
                        mimeTypes.Add ("cxx", "text/plain");
@@ -148,7 +146,6 @@ namespace System.Web
                        mimeTypes.Add ("iefs", "image/ief");
                        mimeTypes.Add ("iges", "application/iges");
                        mimeTypes.Add ("igs", "application/iges");
-                       mimeTypes.Add ("igs", "model/iges");
                        mimeTypes.Add ("ima", "application/x-ima");
                        mimeTypes.Add ("imap", "application/x-httpd-imap");
                        mimeTypes.Add ("inf ", "application/inf");
@@ -183,7 +180,6 @@ namespace System.Web
                        mimeTypes.Add ("lsx", "text/x-la-asf");
                        mimeTypes.Add ("ltx", "application/x-latex");
                        mimeTypes.Add ("m", "text/plain");
-                       mimeTypes.Add ("m", "text/x-m");
                        mimeTypes.Add ("m1v", "video/mpeg");
                        mimeTypes.Add ("m2a", "audio/mpeg");
                        mimeTypes.Add ("m2v", "video/mpeg");
@@ -243,7 +239,6 @@ namespace System.Web
                        mimeTypes.Add ("omcr", "application/x-omcregerator");
                        mimeTypes.Add ("p", "text/x-pascal");
                        mimeTypes.Add ("p10", "application/pkcs10");
-                       mimeTypes.Add ("p10", "application/x-pkcs10");
                        mimeTypes.Add ("p12", "application/pkcs-12");
                        mimeTypes.Add ("p7a", "application/x-pkcs7-signature");
                        mimeTypes.Add ("p7c", "application/pkcs7-mime");