Read() public method

public Read ( long offset, char buffer, int offsetInBuffer, int count ) : long
offset long
buffer char
offsetInBuffer int
count int
return long
示例#1
0
        // The Read/Write/Readchar/Writechar simply delegates to SqlChars
        public override int Read(char[] buffer, int offset, int count)
        {
            CheckIfStreamClosed("Read");

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0 || offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0 || count > buffer.Length - offset)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            int icharsRead = (int)_sqlchars.Read(_lPosition, buffer, offset, count);

            _lPosition += icharsRead;

            return(icharsRead);
        }
示例#2
0
		public void Read_NegativeCountTest ()
		{
			char [] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
			SqlChars chars = new SqlChars (c1);
			char [] c2 = new char [5];
			
			chars.Read (0, c2, 0, -1);
			Assert.Fail ("#11 Should throw ArgumentOutOfRangeException");
		}
示例#3
0
		public void Read_NullBufferAndInstanceValueTest ()
		{
			char [] c2 = null;
			SqlChars chars = new SqlChars ();
			
			chars.Read (0, c2, 8, 4);
		}
示例#4
0
		public void Read_SuccessTest2 ()
		{
			char [] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
			SqlChars chars = new SqlChars (c1);
			char [] c2 = new char [10];
			
			chars.Read (5, c2, 0, 10);
			Assert.AreEqual (chars.Value [5], c2 [0], "#8 Should be same");
			Assert.AreEqual (chars.Value [9], c2 [4], "#9 Should be same");
		}
示例#5
0
		public void Read_NullInstanceValueTest ()
		{
			char [] c2 = new char [5];
			SqlChars chars = new SqlChars ();
			
			chars.Read (0, c2, 8, 4);
			Assert.Fail ("#7 Should throw SqlNullValueException");
		}
示例#6
0
		public void Read_InvalidOffsetInBufferTest ()
		{
			char [] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
			SqlChars chars = new SqlChars (c1);
			char [] c2 = new char [5];

			chars.Read (0, c2, 8, 4);
			Assert.Fail ("#6 Should throw ArgumentOutOfRangeException");
		}
示例#7
0
		public void Read_NullBufferTest ()
		{
			char [] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
			SqlChars chars = new SqlChars (c1);
			char [] c2 = null;
			
			chars.Read (0, c2, 0, 10);
			Assert.Fail ("#2 Should throw ArgumentNullException");
		}
示例#8
0
		public void Read_NegativeOffsetInBufferTest ()
		{
            ExceptionAssert.Throws<ArgumentOutOfRangeException>(
		        delegate
		            {
		                char [] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
		                SqlChars chars = new SqlChars (c1);
		                char [] c2 = new char [5];
			
		                chars.Read (0, c2, -1, 4);
		                Assert.Fail ("#5 Should throw ArgumentOutOfRangeException");
		            });
		}
 private static void SetSqlChars_Unchecked(SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlChars value, int offset, int length)
 {
     if (value.IsNull)
     {
         setters.SetDBNull(sink, ordinal);
         sink.ProcessMessagesAndThrow();
     }
     else
     {
         int num4;
         long num5;
         if ((length > 0xfa0) || (length < 0))
         {
             num4 = 0xfa0;
         }
         else
         {
             num4 = length;
         }
         char[] buffer = new char[num4];
         long num2 = 1L;
         long num = offset;
         for (long i = 0L; ((length < 0) || (i < length)) && ((0L != (num5 = value.Read(num, buffer, 0, num4))) && (0L != num2)); i += num2)
         {
             num2 = setters.SetChars(sink, ordinal, num, buffer, 0, (int) num5);
             sink.ProcessMessagesAndThrow();
             num += num2;
         }
         setters.SetCharsLength(sink, ordinal, num);
         sink.ProcessMessagesAndThrow();
     }
 }
示例#10
0
        public void Read_NullBufferAndInstanceValueTest()
        {
            char[] c2 = null;
            SqlChars chars = new SqlChars();

            Assert.Throws<SqlNullValueException>(() => chars.Read(0, c2, 8, 4));
        }
示例#11
0
        public void Read_InvalidCountTest2()
        {
            char[] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
            SqlChars chars = new SqlChars(c1);
            char[] c2 = new char[5];

            Assert.Throws<ArgumentOutOfRangeException>(() => chars.Read(0, c2, 3, 4));
        }
示例#12
0
        public void Read_NegativeOffsetInBufferTest()
        {
            char[] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
            SqlChars chars = new SqlChars(c1);
            char[] c2 = new char[5];

            Assert.Throws<ArgumentOutOfRangeException>(() => chars.Read(0, c2, -1, 4));
        }
示例#13
0
        public void Read_NullBufferTest()
        {
            char[] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
            SqlChars chars = new SqlChars(c1);
            char[] c2 = null;

            Assert.Throws<ArgumentNullException>(() => chars.Read(0, c2, 0, 10));
        }
示例#14
0
		public void Read_NullBufferAndInstanceValueTest ()
		{
			char [] c2 = null;
			SqlChars chars = new SqlChars ();
			
			chars.Read (0, c2, 8, 4);
			Assert.Fail ("#10 Should throw ArgumentNullException");
		}
示例#15
0
		public void Read_InvalidCountTest2 ()
		{
			char [] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
			SqlChars chars = new SqlChars (c1);
			char [] c2 = new char [5]; 

			chars.Read (0, c2, 3, 4);
			Assert.Fail ("#12 Should throw ArgumentOutOfRangeException");
		}
示例#16
0
		public void Read_SuccessTest1 ()
		{
			char [] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
			SqlChars chars = new SqlChars (c1);
			char [] c2 = new char [10];

			chars.Read (0, c2, 0, (int) chars.Length);
			Assert.AreEqual (chars.Value [5], c2 [5], "#1 Should be equal");
		}
示例#17
0
        private static void SetSqlChars_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlChars value, int offset, int length ) {
            if ( value.IsNull ) {
                setters.SetDBNull( sink, ordinal );
                sink.ProcessMessagesAndThrow();
            }
            else {
                int chunkSize;
                if ( length > __maxCharChunkSize || length < 0 ) {
                    chunkSize = __maxCharChunkSize;
                }
                else {
                    chunkSize = checked( (int)length );
                }

                char[] buffer = new char[ chunkSize ];
                long charsRead;
                long charsWritten = 1;  // prime value to get into write loop
                long currentOffset = offset;
                long lengthWritten = 0;

                while ( (length < 0  || lengthWritten < length) &&
                        0 != ( charsRead = value.Read( currentOffset, buffer, 0, chunkSize ) ) &&
                        0 != charsWritten ) {
                    charsWritten = setters.SetChars( sink, ordinal, currentOffset, buffer, 0, checked( (int) charsRead ) );
                    sink.ProcessMessagesAndThrow();
                    checked{ currentOffset += charsWritten; }
                    checked{ lengthWritten += charsWritten;}
                }

                // Make sure to trim any left-over data
                setters.SetCharsLength( sink, ordinal, currentOffset );
                sink.ProcessMessagesAndThrow();
            }
        }
示例#18
0
		public void Read_InvalidCountTest1 ()
		{
		    ExceptionAssert.Throws<ArgumentOutOfRangeException>(
		        delegate
		            {
		                char[] c1 = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
		                SqlChars chars = new SqlChars(c1);
		                char[] c2 = new char[5];

		                chars.Read(0, c2, 0, 10);
		                Assert.Fail("#3 Should throw ArgumentOutOfRangeException");
		            });
		}