示例#1
0
 /// <summary>
 /// Create a new IOStreamStreamReader from the given System.IO.Stream.   Optionally you can specify the size of the read buffer
 /// The stream will be closed by the IOStreamStreamReader when it is closed.
 /// </summary>
 public IOStreamStreamReader(Stream inputStream, int bufferSize = defaultBufferSize, bool leaveOpen = false, SerializationConfiguration config = null, StreamReaderAlignment alignment = StreamReaderAlignment.EightBytes)
     : base(new byte[bufferSize + (int)alignment], 0, 0, config)
 {
     align = (int)alignment;
     Debug.Assert(bufferSize % align == 0);
     this.inputStream = inputStream;
     this.leaveOpen   = leaveOpen;
 }
示例#2
0
 /// <summary>
 /// Create a new PinnedStreamReader that gets its data from a given System.IO.Stream.  You can optionally set the size of the read buffer.
 /// The stream will be closed by the PinnedStreamReader when it is closed.
 /// </summary>
 public PinnedStreamReader(Stream inputStream, int bufferSize = defaultBufferSize, SerializationConfiguration config = null, StreamReaderAlignment alignment = StreamReaderAlignment.EightBytes)
     : base(inputStream, bufferSize, config: config, alignment: alignment)
 {
     // Pin the array
     pinningHandle = System.Runtime.InteropServices.GCHandle.Alloc(bytes, System.Runtime.InteropServices.GCHandleType.Pinned);
     fixed(byte *bytesAsPtr = &bytes[0])
     {
         bufferStart = bytesAsPtr;
     }
 }