| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
using System; |
| 12 |
using System.IO; |
| 13 |
|
| 14 |
namespace Microsoft.Cci.Pdb { |
| 15 |
internal class DataStream { |
| 16 |
internal DataStream() { |
| 17 |
} |
| 18 |
|
| 19 |
internal DataStream(int contentSize, BitAccess bits, int count) { |
| 20 |
this.contentSize = contentSize; |
| 21 |
if (count > 0) { |
| 22 |
this.pages = new int[count]; |
| 23 |
bits.ReadInt32(this.pages); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
internal void Read(PdbReader reader, BitAccess bits) { |
| 28 |
bits.MinCapacity(contentSize); |
| 29 |
Read(reader, 0, bits.Buffer, 0, contentSize); |
| 30 |
} |
| 31 |
|
| 32 |
internal void Read(PdbReader reader, int position, |
| 33 |
byte[] bytes, int offset, int data) { |
| 34 |
if (position + data > contentSize) { |
| 35 |
throw new PdbException("DataStream can't read off end of stream. " + |
| 36 |
"(pos={0},siz={1})", |
| 37 |
position, data); |
| 38 |
} |
| 39 |
if (position == contentSize) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
int left = data; |
| 44 |
int page = position / reader.pageSize; |
| 45 |
int rema = position % reader.pageSize; |
| 46 |
|
| 47 |
|
| 48 |
if (rema != 0) { |
| 49 |
int todo = reader.pageSize - rema; |
| 50 |
if (todo > left) { |
| 51 |
todo = left; |
| 52 |
} |
| 53 |
|
| 54 |
reader.Seek(pages[page], rema); |
| 55 |
reader.Read(bytes, offset, todo); |
| 56 |
|
| 57 |
offset += todo; |
| 58 |
left -= todo; |
| 59 |
page++; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
while (left > 0) { |
| 64 |
int todo = reader.pageSize; |
| 65 |
if (todo > left) { |
| 66 |
todo = left; |
| 67 |
} |
| 68 |
|
| 69 |
reader.Seek(pages[page], 0); |
| 70 |
reader.Read(bytes, offset, todo); |
| 71 |
|
| 72 |
offset += todo; |
| 73 |
left -= todo; |
| 74 |
page++; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
internal int Length { |
| 101 |
get { return contentSize; } |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
internal int contentSize; |
| 109 |
internal int[] pages; |
| 110 |
} |
| 111 |
} |