Read() 공개 메소드

Reads a single character from the stream, using the character encoding for this reader. If no characters have been fully read by the time the stream ends, -1 is returned.
public Read ( ) : int
리턴 int
        public void ReadCharsBeyondInternalBufferSize()
        {
            MemoryStream stream = new MemoryStream(TestBytes);
            EndianBinaryReader subject = new EndianBinaryReader(EndianBitConverter.Little, stream);

            char[] chars = new char[TestString.Length];
            subject.Read(chars, 0, chars.Length);
            Assert.AreEqual(TestString, new string(chars));
        }
        public void ReadCharsBeyondProvidedBufferSize()
        {
            MemoryStream stream = new MemoryStream(TestBytes);
            EndianBinaryReader subject = new EndianBinaryReader(EndianBitConverter.Little, stream);

            char[] chars = new char[TestString.Length-1];
            try
            {
                subject.Read(chars, 0, TestString.Length);
                Assert.Fail("Expected exception");
            }
            catch (ArgumentException)
            {
                // Expected
            }
        }
예제 #3
0
        internal long ReadLongBuffer(byte[] buffer, long len, EndianBinaryReader reader)
        {
            // TODO check whole function

            byte[] temp = (len > int.MaxValue ? new byte[int.MaxValue] : null);

            long byt = 0;
            while (byt < len)
            {
                int n;
                long missing = len - byt;
                int missing32 = (missing > int.MaxValue ? int.MaxValue : (int)missing);
                if (temp != null) // Use a temporary buffer so offsets fit in an int
                {
                    n = reader.Read(temp, 0, missing32);
                    Array.Copy(temp, 0, buffer, byt, n);
                }
                else // Total package is shorter than int.MaxValue
                {
                    n = reader.Read(buffer, (int)byt, (int)missing);
                }
                byt += n;
            }

            return byt;
        }