Ejemplo n.º 1
0
        // spool a Stream into a scratch stream from the Smi interface and return it as a SqlStreamChars
        internal static SqlStreamChars CopyIntoNewSmiScratchStreamChars( Stream source, SmiEventSink_Default sink, SmiContext context )  {
            SqlClientWrapperSmiStreamChars dest = new SqlClientWrapperSmiStreamChars( 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 SqlStreamChars CopyIntoNewSmiScratchStreamChars(Stream source, SmiEventSink_Default sink, SmiContext context)
 {
     int length;
     int num2;
     SqlClientWrapperSmiStreamChars chars = new SqlClientWrapperSmiStreamChars(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)
     {
         chars.Write(buffer, 0, num2);
     }
     chars.Flush();
     chars.Seek(0L, SeekOrigin.Begin);
     return chars;
 }