Beispiel #1
0
        // spool a Stream into a scratch stream from the Smi interface and return it as a Stream
        internal static Stream CopyIntoNewSmiScratchStream( Stream source, SmiEventSink_Default sink, SmiContext context )  {
            Stream dest;
            if (null == context) {
                dest = new MemoryStream();
            }
            else {
                dest = new SqlClientWrapperSmiStream( sink, context.GetScratchStream( sink ) );
            }

            int chunkSize;
            if ( source.CanSeek && __maxByteChunkSize > source.Length ) {
                chunkSize = unchecked( (int) source.Length );  // unchecked cast is safe due to check on line above
            }
            else {
                chunkSize = __maxByteChunkSize;
            }

            byte[] copyBuffer = new byte[chunkSize];
            int bytesRead;
            while ( 0 != ( bytesRead = source.Read( copyBuffer, 0, chunkSize ) ) ) {
                dest.Write( copyBuffer, 0, bytesRead );
            }
            dest.Flush();

            // SQLBU 494334
            //  Need to re-wind scratch stream to beginning before returning
            dest.Seek(0, SeekOrigin.Begin);

            return dest;
        }
 internal static Stream CopyIntoNewSmiScratchStream(Stream source, SmiEventSink_Default sink, SmiContext context)
 {
     Stream stream;
     int length;
     int num2;
     if (context == null)
     {
         stream = new MemoryStream();
     }
     else
     {
         stream = new SqlClientWrapperSmiStream(sink, context.GetScratchStream(sink));
     }
     if (source.CanSeek && (0x1f40L > source.Length))
     {
         length = (int) source.Length;
     }
     else
     {
         length = 0x1f40;
     }
     byte[] buffer = new byte[length];
     while ((num2 = source.Read(buffer, 0, length)) != 0)
     {
         stream.Write(buffer, 0, num2);
     }
     stream.Flush();
     stream.Seek(0L, SeekOrigin.Begin);
     return stream;
 }