2
using System.Collections.Generic;
4
using Be.Windows.Forms;
7
namespace StructuredStorageExplorer
9
public class StreamDataProvider : IByteProvider
14
CFStream _modifiedStream;
17
/// Contains information about changes.
22
/// Contains a byte collection.
24
ByteCollection _bytes;
28
/// Initializes a new instance of the DynamicByteProvider class.
30
/// <param name="bytes"></param>
31
public StreamDataProvider(CFStream modifiedStream)
33
_bytes = new ByteCollection(modifiedStream.GetData());
34
_modifiedStream = modifiedStream;
38
/// Raises the Changed event.
40
void OnChanged(EventArgs e)
49
/// Raises the LengthChanged event.
51
void OnLengthChanged(EventArgs e)
53
if (LengthChanged != null)
54
LengthChanged(this, e);
58
/// Gets the byte collection.
60
public ByteCollection Bytes
62
get { return _bytes; }
65
#region IByteProvider Members
67
/// True, when changes are done.
69
public bool HasChanges()
77
public void ApplyChanges()
81
_modifiedStream.SetData(this._bytes.ToArray());
85
/// Occurs, when the write buffer contains new changes.
87
public event EventHandler Changed;
90
/// Occurs, when InsertBytes or DeleteBytes method is called.
92
public event EventHandler LengthChanged;
96
/// Reads a byte from the byte collection.
98
/// <param name="index">the index of the byte to read</param>
99
/// <returns>the byte</returns>
100
public byte ReadByte(long index)
101
{ return _bytes[(int)index]; }
104
/// Write a byte into the byte collection.
106
/// <param name="index">the index of the byte to write.</param>
107
/// <param name="value">the byte</param>
108
public void WriteByte(long index, byte value)
110
_bytes[(int)index] = value;
111
OnChanged(EventArgs.Empty);
115
/// Deletes bytes from the byte collection.
117
/// <param name="index">the start index of the bytes to delete.</param>
118
/// <param name="length">the length of bytes to delete.</param>
119
public void DeleteBytes(long index, long length)
121
int internal_index = (int)Math.Max(0, index);
122
int internal_length = (int)Math.Min((int)Length, length);
123
_bytes.RemoveRange(internal_index, internal_length);
125
OnLengthChanged(EventArgs.Empty);
126
OnChanged(EventArgs.Empty);
130
/// Inserts byte into the byte collection.
132
/// <param name="index">the start index of the bytes in the byte collection</param>
133
/// <param name="bs">the byte array to insert</param>
134
public void InsertBytes(long index, byte[] bs)
136
_bytes.InsertRange((int)index, bs);
138
OnLengthChanged(EventArgs.Empty);
139
OnChanged(EventArgs.Empty);
143
/// Gets the length of the bytes in the byte collection.
156
public bool SupportsWriteByte()
164
public bool SupportsInsertBytes()
172
public bool SupportsDeleteBytes()