Kinetica   C#   API  Version 7.2.3.0
ByteBufferInputStream.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using System.IO;
21 
22 namespace Avro.IO
23 {
25  {
26  private readonly IList<MemoryStream> _buffers;
27  private int _currentBuffer;
28 
29  public ByteBufferInputStream(IList<MemoryStream> buffers)
30  {
31  _buffers = buffers;
32  }
33 
34  public override int Read(byte[] b, int off, int len)
35  {
36  if (len == 0) return 0;
37  MemoryStream buffer = GetNextNonEmptyBuffer();
38  long remaining = buffer.Length - buffer.Position;
39  if (len > remaining)
40  {
41  int remainingCheck = buffer.Read(b, off, (int) remaining);
42 
43  if(remainingCheck != remaining)
44  throw new InvalidDataException(string.Format("remainingCheck [{0}] and remaining[{1}] are different.",
45  remainingCheck, remaining));
46  return (int)remaining;
47  }
48 
49  int lenCheck = buffer.Read(b, off, len);
50 
51  if (lenCheck != len)
52  throw new InvalidDataException(string.Format("lenCheck [{0}] and len[{1}] are different.",
53  lenCheck, len));
54 
55  return len;
56  }
57 
58  private MemoryStream GetNextNonEmptyBuffer()
59  {
60  while (_currentBuffer < _buffers.Count)
61  {
62  MemoryStream buffer = _buffers[_currentBuffer];
63  if (buffer.Position < buffer.Length)
64  return buffer;
65 
66  _currentBuffer++;
67  }
68  throw new EndOfStreamException();
69  }
70 
71  public override long Length
72  {
73  get { throw new NotSupportedException(); }
74  }
75  }
76 }
ByteBufferInputStream(IList< MemoryStream > buffers)
override int Read(byte[] b, int off, int len)