Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
BlockingBufferedStream.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.IO;
4 
5 namespace SiliconStudio.Paradox.Graphics.Regression
6 {
8  {
9  private readonly Stream innerStream;
10 
11  /// <inheritdoc/>
12  public BlockingBufferStream(Stream innerStream)
13  {
14  this.innerStream = innerStream;
15  }
16 
17  /// <inheritdoc/>
18  public override bool CanRead
19  {
20  get { return innerStream.CanRead; }
21  }
22 
23  /// <inheritdoc/>
24  public override bool CanSeek
25  {
26  get { return innerStream.CanSeek; }
27  }
28 
29  /// <inheritdoc/>
30  public override bool CanWrite
31  {
32  get { return innerStream.CanWrite; }
33  }
34 
35  /// <inheritdoc/>
36  public override bool CanTimeout
37  {
38  get { return innerStream.CanTimeout; }
39  }
40 
41  /// <inheritdoc/>
42  public override long Length
43  {
44  get { return innerStream.Length; }
45  }
46 
47  /// <inheritdoc/>
48  public override long Position
49  {
50  get { return innerStream.Position; }
51  set { innerStream.Position = value; }
52  }
53 
54  /// <inheritdoc/>
55  public override void Flush()
56  {
57  innerStream.Flush();
58  }
59 
60  public override int Read(byte[] buffer, int offset, int count)
61  {
62  // Read in multiple steps if necessary
63  var totalByteRead = 0;
64  while (count > 0)
65  {
66  var byteRead = innerStream.Read(buffer, offset, count);
67  if (byteRead == 0 && totalByteRead == 0)
68  return 0;
69 
70  offset += byteRead;
71  count -= byteRead;
72  totalByteRead += byteRead;
73  }
74 
75  return totalByteRead;
76  }
77 
78  /// <inheritdoc/>
79  public override long Seek(long offset, SeekOrigin origin)
80  {
81  return innerStream.Seek(offset, origin);
82  }
83 
84  /// <inheritdoc/>
85  public override void SetLength(long value)
86  {
87  innerStream.SetLength(value);
88  }
89 
90  /// <inheritdoc/>
91  public override void Write(byte[] buffer, int offset, int count)
92  {
93  innerStream.Write(buffer, offset, count);
94  }
95 
96  /// <inheritdoc/>
97  public override int ReadByte()
98  {
99  return innerStream.ReadByte();
100  }
101 
102  /// <inheritdoc/>
103  public override void WriteByte(byte value)
104  {
105  innerStream.WriteByte(value);
106  }
107 
108 #if !SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
109 
110  /// <inheritdoc/>
111  public override void Close()
112  {
113  innerStream.Close();
114  base.Close();
115  }
116 
117 #endif
118 
119  /// <inheritdoc/>
120  protected override void Dispose(bool disposing)
121  {
122  if (disposing)
123  innerStream.Dispose();
124  base.Dispose(disposing);
125  }
126  }
127 }
override int Read(byte[] buffer, int offset, int count)
_In_ size_t count
Definition: DirectXTexP.h:174
override void Write(byte[] buffer, int offset, int count)