Skip to content

Commit c6ba517

Browse files
committed
New PipeAll with explicit buffer size
- increase default buffer size
1 parent a2d8f59 commit c6ba517

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

crypto/src/util/io/Streams.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Org.BouncyCastle.Utilities.IO
55
{
66
public sealed class Streams
77
{
8-
private const int BufferSize = 512;
8+
private const int BufferSize = 4096;
99

1010
private Streams()
1111
{
@@ -51,10 +51,24 @@ public static int ReadFully(Stream inStr, byte[] buf, int off, int len)
5151
return totalRead;
5252
}
5353

54-
public static void PipeAll(Stream inStr, Stream outStr)
54+
/// <summary>Write the full contents of inStr to the destination stream outStr.</summary>
55+
/// <param name="inStr">Source stream.</param>
56+
/// <param name="outStr">Destination stream.</param>
57+
/// <exception cref="IOException">In case of IO failure.</exception>
58+
public static void PipeAll(Stream inStr, Stream outStr)
5559
{
56-
byte[] bs = new byte[BufferSize];
57-
int numRead;
60+
PipeAll(inStr, outStr, BufferSize);
61+
}
62+
63+
/// <summary>Write the full contents of inStr to the destination stream outStr.</summary>
64+
/// <param name="inStr">Source stream.</param>
65+
/// <param name="outStr">Destination stream.</param>
66+
/// <param name="bufferSize">The size of temporary buffer to use.</param>
67+
/// <exception cref="IOException">In case of IO failure.</exception>
68+
public static void PipeAll(Stream inStr, Stream outStr, int bufferSize)
69+
{
70+
byte[] bs = new byte[bufferSize];
71+
int numRead;
5872
while ((numRead = inStr.Read(bs, 0, bs.Length)) > 0)
5973
{
6074
outStr.Write(bs, 0, numRead);

0 commit comments

Comments
 (0)