From c6ba5170272dfa4470af11a3ff0fef99a22b1a31 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 9 Jun 2021 21:39:17 +0700 Subject: New PipeAll with explicit buffer size - increase default buffer size --- crypto/src/util/io/Streams.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/crypto/src/util/io/Streams.cs b/crypto/src/util/io/Streams.cs index 506b2489f..a86367e56 100644 --- a/crypto/src/util/io/Streams.cs +++ b/crypto/src/util/io/Streams.cs @@ -5,7 +5,7 @@ namespace Org.BouncyCastle.Utilities.IO { public sealed class Streams { - private const int BufferSize = 512; + private const int BufferSize = 4096; private Streams() { @@ -51,10 +51,24 @@ namespace Org.BouncyCastle.Utilities.IO return totalRead; } - public static void PipeAll(Stream inStr, Stream outStr) + /// Write the full contents of inStr to the destination stream outStr. + /// Source stream. + /// Destination stream. + /// In case of IO failure. + public static void PipeAll(Stream inStr, Stream outStr) { - byte[] bs = new byte[BufferSize]; - int numRead; + PipeAll(inStr, outStr, BufferSize); + } + + /// Write the full contents of inStr to the destination stream outStr. + /// Source stream. + /// Destination stream. + /// The size of temporary buffer to use. + /// In case of IO failure. + public static void PipeAll(Stream inStr, Stream outStr, int bufferSize) + { + byte[] bs = new byte[bufferSize]; + int numRead; while ((numRead = inStr.Read(bs, 0, bs.Length)) > 0) { outStr.Write(bs, 0, numRead); -- cgit 1.4.1