summary refs log tree commit diff
path: root/crypto/src/bcpg/BcpgOutputStream.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/bcpg/BcpgOutputStream.cs')
-rw-r--r--crypto/src/bcpg/BcpgOutputStream.cs75
1 files changed, 35 insertions, 40 deletions
diff --git a/crypto/src/bcpg/BcpgOutputStream.cs b/crypto/src/bcpg/BcpgOutputStream.cs
index 738c28211..fbce0820e 100644
--- a/crypto/src/bcpg/BcpgOutputStream.cs
+++ b/crypto/src/bcpg/BcpgOutputStream.cs
@@ -215,8 +215,7 @@ namespace Org.BouncyCastle.Bcpg
             }
         }
 
-        private void PartialFlush(
-            bool isLast)
+        private void PartialFlush(bool isLast)
         {
             if (isLast)
             {
@@ -232,79 +231,75 @@ namespace Org.BouncyCastle.Bcpg
             partialOffset = 0;
         }
 
-		private void WritePartial(
-            byte b)
+        private void PartialWrite(byte[] buffer, int offset, int count)
         {
-            if (partialOffset == partialBufferLength)
-            {
-                PartialFlush(false);
-            }
-
-			partialBuffer[partialOffset++] = b;
-        }
+            Streams.ValidateBufferArguments(buffer, offset, count);
 
-		private void WritePartial(
-            byte[]	buffer,
-            int		off,
-            int		len)
-        {
             if (partialOffset == partialBufferLength)
             {
                 PartialFlush(false);
             }
 
-            if (len <= (partialBufferLength - partialOffset))
+            if (count <= (partialBufferLength - partialOffset))
             {
-                Array.Copy(buffer, off, partialBuffer, partialOffset, len);
-                partialOffset += len;
+                Array.Copy(buffer, offset, partialBuffer, partialOffset, count);
+                partialOffset += count;
             }
             else
             {
                 int diff = partialBufferLength - partialOffset;
-                Array.Copy(buffer, off, partialBuffer, partialOffset, diff);
-                off += diff;
-                len -= diff;
+                Array.Copy(buffer, offset, partialBuffer, partialOffset, diff);
+                offset += diff;
+                count -= diff;
                 PartialFlush(false);
-                while (len > partialBufferLength)
+                while (count > partialBufferLength)
                 {
-                    Array.Copy(buffer, off, partialBuffer, 0, partialBufferLength);
-                    off += partialBufferLength;
-                    len -= partialBufferLength;
+                    Array.Copy(buffer, offset, partialBuffer, 0, partialBufferLength);
+                    offset += partialBufferLength;
+                    count -= partialBufferLength;
                     PartialFlush(false);
                 }
-                Array.Copy(buffer, off, partialBuffer, 0, len);
-                partialOffset += len;
+                Array.Copy(buffer, offset, partialBuffer, 0, count);
+                partialOffset += count;
             }
         }
-        public override void WriteByte(
-			byte value)
+
+        private void PartialWriteByte(byte value)
+        {
+            if (partialOffset == partialBufferLength)
+            {
+                PartialFlush(false);
+            }
+
+            partialBuffer[partialOffset++] = value;
+        }
+
+        public override void Write(byte[] buffer, int offset, int count)
         {
             if (partialBuffer != null)
             {
-                WritePartial(value);
+                PartialWrite(buffer, offset, count);
             }
             else
             {
-                outStr.WriteByte(value);
+                outStr.Write(buffer, offset, count);
             }
         }
-        public override void Write(
-            byte[]	buffer,
-            int		offset,
-            int		count)
+
+        public override void WriteByte(byte value)
         {
             if (partialBuffer != null)
             {
-                WritePartial(buffer, offset, count);
+                PartialWriteByte(value);
             }
             else
             {
-                outStr.Write(buffer, offset, count);
+                outStr.WriteByte(value);
             }
         }
 
-		// Additional helper methods to write primitive types
-		internal virtual void WriteShort(
+        // Additional helper methods to write primitive types
+        internal virtual void WriteShort(
 			short n)
 		{
 			this.Write(