Fix build_init vcxproj to correctly detect changes in config.h.
[mono.git] / mcs / class / System.IO.Compression / SharpCompress / IO / MarkingBinaryReader.cs
1 using System;
2 using System.IO;
3 using System.Linq;
4
5 namespace SharpCompress.IO
6 {
7     internal class MarkingBinaryReader : BinaryReader
8     {
9
10         public MarkingBinaryReader(Stream stream)
11             : base(stream)
12         {
13         }
14
15         public long CurrentReadByteCount { get; private set; }
16
17         public void Mark()
18         {
19             CurrentReadByteCount = 0;
20         }
21
22         public override int Read()
23         {
24             throw new NotImplementedException();
25         }
26
27         public override int Read(byte[] buffer, int index, int count)
28         {
29             throw new NotImplementedException();
30         }
31
32         public override int Read(char[] buffer, int index, int count)
33         {
34             throw new NotImplementedException();
35         }
36
37         public override bool ReadBoolean()
38         {
39             return BitConverter.ToBoolean(ReadBytes(1), 0);
40         }
41
42         public override byte ReadByte()
43         {
44             return ReadBytes(1).Single();
45         }
46
47         public override byte[] ReadBytes(int count)
48         {
49             CurrentReadByteCount += count;
50             var bytes = base.ReadBytes(count);
51             if (bytes.Length != count)
52             {
53                 throw new EndOfStreamException(string.Format("Could not read the requested amount of bytes.  End of stream reached. Requested: {0} Read: {1}", count, bytes.Length));
54             }
55             return bytes;
56         }
57
58         public override char ReadChar()
59         {
60             throw new NotImplementedException();
61         }
62
63         public override char[] ReadChars(int count)
64         {
65             throw new NotImplementedException();
66         }
67
68 #if !PORTABLE
69         public override decimal ReadDecimal()
70         {
71             return ByteArrayToDecimal(ReadBytes(16), 0);
72         }
73
74         private decimal ByteArrayToDecimal(byte[] src, int offset)
75         {
76             //http://stackoverflow.com/a/16984356/385387
77             var i1 = BitConverter.ToInt32(src, offset);
78             var i2 = BitConverter.ToInt32(src, offset + 4);
79             var i3 = BitConverter.ToInt32(src, offset + 8);
80             var i4 = BitConverter.ToInt32(src, offset + 12);
81
82             return new decimal(new[] { i1, i2, i3, i4 });
83         }
84 #endif
85
86         public override double ReadDouble()
87         {
88             return BitConverter.ToDouble(ReadBytes(8), 0);
89         }
90
91         public override short ReadInt16()
92         {
93             return BitConverter.ToInt16(ReadBytes(2), 0);
94         }
95
96         public override int ReadInt32()
97         {
98             return BitConverter.ToInt32(ReadBytes(4), 0);
99         }
100
101         public override long ReadInt64()
102         {
103             return BitConverter.ToInt64(ReadBytes(8), 0);
104         }
105
106         public override sbyte ReadSByte()
107         {
108             return (sbyte)ReadByte();
109         }
110
111         public override float ReadSingle()
112         {
113             return BitConverter.ToSingle(ReadBytes(4), 0);
114         }
115
116         public override string ReadString()
117         {
118             throw new NotImplementedException();
119         }
120
121         public override ushort ReadUInt16()
122         {
123             return BitConverter.ToUInt16(ReadBytes(2), 0);
124         }
125
126         public override uint ReadUInt32()
127         {
128             return BitConverter.ToUInt32(ReadBytes(4), 0);
129         }
130
131         public override ulong ReadUInt64()
132         {
133             return BitConverter.ToUInt64(ReadBytes(8), 0);
134         }
135     }
136 }