summary refs log tree commit diff
path: root/crypto/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/util')
-rw-r--r--crypto/src/util/Platform.cs18
-rw-r--r--crypto/src/util/io/FilterStream.cs2
-rw-r--r--crypto/src/util/io/TeeInputStream.cs6
-rw-r--r--crypto/src/util/io/TeeOutputStream.cs6
-rw-r--r--crypto/src/util/zlib/ZDeflaterOutputStream.cs2
-rw-r--r--crypto/src/util/zlib/ZInflaterInputStream.cs2
-rw-r--r--crypto/src/util/zlib/ZInputStream.cs2
-rw-r--r--crypto/src/util/zlib/ZOutputStream.cs2
8 files changed, 28 insertions, 12 deletions
diff --git a/crypto/src/util/Platform.cs b/crypto/src/util/Platform.cs
index bfed0950a..82446b296 100644
--- a/crypto/src/util/Platform.cs
+++ b/crypto/src/util/Platform.cs
@@ -19,7 +19,7 @@ namespace Org.BouncyCastle.Utilities
             MemoryStream buf = new MemoryStream();
             StreamWriter w = new StreamWriter(buf, Encoding.UTF8);
             w.WriteLine();
-            w.Close();
+            Dispose(w);
             byte[] bs = buf.ToArray();
             return Encoding.UTF8.GetString(bs, 0, bs.Length);
         }
@@ -184,5 +184,21 @@ namespace Org.BouncyCastle.Utilities
         }
 
         internal static readonly string NewLine = GetNewLine();
+
+#if PORTABLE
+        internal static void Dispose(IDisposable d)
+        {
+            d.Dispose();
+        }
+#else
+        internal static void Dispose(Stream s)
+        {
+            s.Close();
+        }
+        internal static void Dispose(TextWriter t)
+        {
+            t.Close();
+        }
+#endif
     }
 }
diff --git a/crypto/src/util/io/FilterStream.cs b/crypto/src/util/io/FilterStream.cs
index 260ce1789..c5d6a1cba 100644
--- a/crypto/src/util/io/FilterStream.cs
+++ b/crypto/src/util/io/FilterStream.cs
@@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Utilities.IO
         }
         public override void Close()
         {
-            s.Close();
+            Platform.Dispose(s);
         }
         public override void Flush()
         {
diff --git a/crypto/src/util/io/TeeInputStream.cs b/crypto/src/util/io/TeeInputStream.cs
index 373df4502..b344be8a8 100644
--- a/crypto/src/util/io/TeeInputStream.cs
+++ b/crypto/src/util/io/TeeInputStream.cs
@@ -20,11 +20,11 @@ namespace Org.BouncyCastle.Utilities.IO
 
 		public override void Close()
 		{
-			input.Close();
-			tee.Close();
+            Platform.Dispose(input);
+            Platform.Dispose(tee);
 		}
 
-		public override int Read(byte[] buf, int off, int len)
+        public override int Read(byte[] buf, int off, int len)
 		{
 			int i = input.Read(buf, off, len);
 
diff --git a/crypto/src/util/io/TeeOutputStream.cs b/crypto/src/util/io/TeeOutputStream.cs
index fe3a7586a..75d1d305d 100644
--- a/crypto/src/util/io/TeeOutputStream.cs
+++ b/crypto/src/util/io/TeeOutputStream.cs
@@ -20,11 +20,11 @@ namespace Org.BouncyCastle.Utilities.IO
 
 		public override void Close()
 		{
-			output.Close();
-			tee.Close();
+            Platform.Dispose(output);
+            Platform.Dispose(tee);
 		}
 
-		public override void Write(byte[] buffer, int offset, int count)
+        public override void Write(byte[] buffer, int offset, int count)
 		{
 			output.Write(buffer, offset, count);
 			tee.Write(buffer, offset, count);
diff --git a/crypto/src/util/zlib/ZDeflaterOutputStream.cs b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
index 1d88847bd..7ff6d31c8 100644
--- a/crypto/src/util/zlib/ZDeflaterOutputStream.cs
+++ b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
@@ -143,7 +143,7 @@ namespace Org.BouncyCastle.Utilities.Zlib {
             }
             finally{
                 End();
-                outp.Close();
+                Platform.Dispose(outp);
                 outp=null;
             }
         }
diff --git a/crypto/src/util/zlib/ZInflaterInputStream.cs b/crypto/src/util/zlib/ZInflaterInputStream.cs
index 5a3ff5aa6..170596e63 100644
--- a/crypto/src/util/zlib/ZInflaterInputStream.cs
+++ b/crypto/src/util/zlib/ZInflaterInputStream.cs
@@ -115,7 +115,7 @@ namespace Org.BouncyCastle.Utilities.Zlib {
         }
 
         public override void Close() {
-            inp.Close();
+            Platform.Dispose(inp);
         }
     
         public override int ReadByte() {
diff --git a/crypto/src/util/zlib/ZInputStream.cs b/crypto/src/util/zlib/ZInputStream.cs
index d1e1ba160..f0b3068fc 100644
--- a/crypto/src/util/zlib/ZInputStream.cs
+++ b/crypto/src/util/zlib/ZInputStream.cs
@@ -98,7 +98,7 @@ namespace Org.BouncyCastle.Utilities.Zlib
 			if (!closed)
 			{
 				closed = true;
-				input.Close();
+                Platform.Dispose(input);
 			}
 		}
 
diff --git a/crypto/src/util/zlib/ZOutputStream.cs b/crypto/src/util/zlib/ZOutputStream.cs
index 1d2ead7b3..7b49d6638 100644
--- a/crypto/src/util/zlib/ZOutputStream.cs
+++ b/crypto/src/util/zlib/ZOutputStream.cs
@@ -115,7 +115,7 @@ namespace Org.BouncyCastle.Utilities.Zlib
 			{
 				this.closed = true;
 				End();
-				output.Close();
+                Platform.Dispose(output);
 				output = null;
 			}
 		}