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 } }
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; }