Read() публичный Метод

Read the specified buffer, offset and count.
public Read ( byte buffer, int offset, int count ) : int
buffer byte /// Buffer. ///
offset int /// Offset. ///
count int /// Count. ///
Результат int
Пример #1
0
 public void UpdateLengthIfInputStreamGrowsAfterStartReading() {
     using (var stream = new MemoryStream()) {
         long initialLength = 100;
         long length = initialLength;
         byte[] buffer = new byte[initialLength];
         stream.Write(buffer, 0, buffer.Length);
         using (var progress = new ProgressStream(stream)) {
             progress.PropertyChanged += delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
                 var t = sender as ProgressStream;
                 if (e.PropertyName == Utils.NameOf(() => t.Position)) {
                     Assert.That(t.Position, Is.LessThanOrEqualTo(length));
                     Assert.That(t.Length, Is.LessThanOrEqualTo(length));
                 }
             };
             progress.Read(buffer, 0, buffer.Length / 2);
             stream.Write(buffer, 0, buffer.Length);
             length = length + buffer.Length;
             progress.Read(buffer, 0, buffer.Length / 2);
             progress.Read(buffer, 0, buffer.Length / 2);
             progress.Read(buffer, 0, buffer.Length / 2);
             stream.Write(buffer, 0, buffer.Length);
             length = length + buffer.Length;
             progress.Read(buffer, 0, buffer.Length);
         }
     }
 }
Пример #2
0
 public void Read() {
     using (var stream = new MemoryStream()) {
         byte[] buffer = new byte[10];
         using (var progress = new ProgressStream(stream)) {
             progress.PropertyChanged += delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
                 var p = sender as ProgressStream;
                 if (e.PropertyName == Utils.NameOf(() => p.Position)) {
                     this.positionCalls++;
                     this.position = (long)p.Position;
                 }
             };
             progress.SetLength(buffer.Length * 10);
             progress.Read(buffer, 0, buffer.Length);
             Assert.AreEqual(buffer.Length, this.position);
             Assert.AreEqual(10, progress.Percent);
             progress.Read(buffer, 0, buffer.Length);
             Assert.AreEqual(buffer.Length * 2, this.position);
             Assert.AreEqual(20, progress.Percent);
             progress.Read(buffer, 0, buffer.Length);
             Assert.AreEqual(buffer.Length * 3, this.position);
             Assert.AreEqual(30, progress.Percent);
             progress.Read(buffer, 0, buffer.Length);
             Assert.AreEqual(buffer.Length * 4, this.position);
             Assert.AreEqual(40, progress.Percent);
             progress.Read(buffer, 0, buffer.Length / 2);
             Assert.AreEqual((buffer.Length * 4) + (buffer.Length / 2), this.position);
             Assert.AreEqual(45, progress.Percent);
             progress.Read(buffer, 0, buffer.Length);
             Assert.AreEqual((buffer.Length * 5) + (buffer.Length / 2), this.position);
             Assert.AreEqual(55, progress.Percent);
             progress.SetLength(buffer.Length * 100);
             progress.Read(buffer, 0, buffer.Length);
             Assert.AreEqual((buffer.Length * 6) + (buffer.Length / 2), this.position);
             Assert.AreEqual(6.5, progress.Percent);
         }
     }
 }