Reduced buffer size while hashing to 16K
[pithos-ms-client] / trunk / Pithos.Network / WebExtensions.cs
index 66b8e6d..53612d6 100644 (file)
@@ -10,6 +10,7 @@ namespace Pithos.Network
 {
     public static class WebExtensions
     {
+
         public static string ReadToEnd(this HttpWebResponse response)
         {
             using (var stream = response.GetResponseStream())
@@ -36,7 +37,7 @@ namespace Pithos.Network
             }
         }
 
-        public static TextReader GetLoggedReader(this Stream stream, ILog log, long contentLength)
+        public static TextReader GetLoggedReader(this Stream stream, ILog log)
         {
             var reader = new StreamReader(stream);
             if (!log.IsDebugEnabled)
@@ -44,12 +45,23 @@ namespace Pithos.Network
             
             using (reader)
             {
-                var buffer=new char[contentLength];
-                var read=reader.Read(buffer, 0, (int)contentLength);
-                var body = new string(buffer,0,read); //reader.ReadToEnd();
+                var body = reader.ReadToEnd();
                 log.DebugFormat("JSON response: {0}", body);
                 return new StringReader(body);
             }
         }
+
+
+        public static TOut NullSafe<TIn, TOut>(this TIn obj, Func<TIn, TOut> memberAction)
+        {
+            //Note we should not use obj != null because it can not test value types and also
+            //compiler has to lift the type to a nullable type for doing the comparision with null.
+            return (!EqualityComparer<TIn>.Default.Equals(obj, default(TIn))) ? memberAction(obj) : default(TOut);
+
+        }
+
+
+
+
     }
 }