You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2011/03/17 15:48:24 UTC

svn commit: r1082509 - /chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs

Author: fmui
Date: Thu Mar 17 14:48:24 2011
New Revision: 1082509

URL: http://svn.apache.org/viewvc?rev=1082509&view=rev
Log:
- optimized content encoding

Modified:
    chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs

Modified: chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs
URL: http://svn.apache.org/viewvc/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs?rev=1082509&r1=1082508&r2=1082509&view=diff
==============================================================================
--- chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs (original)
+++ chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-writer.cs Thu Mar 17 14:48:24 2011
@@ -169,25 +169,17 @@ namespace DotCMIS.Binding.AtomPub
 
         private void WriteContent(XmlWriter writer)
         {
-            byte[] byteArray = null;
-
-            if (stream is MemoryStream)
-            {
-                byteArray = ((MemoryStream)stream).ToArray();
-            }
-            else
+            using (BinaryReader br = new BinaryReader(stream))
             {
-                MemoryStream memStream = new MemoryStream();
                 byte[] buffer = new byte[BufferSize];
-                int bytes;
-                while ((bytes = stream.Read(buffer, 0, buffer.Length)) > 0)
+                int readBytes = 0;
+
+                do
                 {
-                    memStream.Write(buffer, 0, bytes);
-                }
-                byteArray = memStream.ToArray();
+                    readBytes = br.Read(buffer, 0, BufferSize);
+                    writer.WriteBase64(buffer, 0, readBytes);
+                } while (BufferSize <= readBytes);
             }
-
-            writer.WriteBase64(byteArray, 0, byteArray.Length);
         }
     }