|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace QiHe.CodeLib
{
public class DataWriter
{
Stream baseStream;
public DataWriter(Stream stream)
{
baseStream = stream;
}
public void WriteByte(byte value)
{
baseStream.WriteByte(value);
}
public void WriteUInt16BE(UInt16 value)
{
byte[] bytes = BitConverter.GetBytes(value);
baseStream.WriteByte(bytes[1]);
baseStream.WriteByte(bytes[0]);
}
public void WriteUInt32BE(UInt32 value)
{
byte[] bytes = BitConverter.GetBytes(value);
baseStream.WriteByte(bytes[3]);
baseStream.WriteByte(bytes[2]);
baseStream.WriteByte(bytes[1]);
baseStream.WriteByte(bytes[0]);
}
public void WriteUInt32LE(UInt32 value)
{
byte[] bytes = BitConverter.GetBytes(value);
baseStream.WriteByte(bytes[0]);
baseStream.WriteByte(bytes[1]);
baseStream.WriteByte(bytes[2]);
baseStream.WriteByte(bytes[3]);
}
public void WriteBytes(byte[] data)
{
baseStream.Write(data, 0, data.Length);
}
public void WriteStream(Stream stream)
{
byte[] buffer = new byte[stream.Length];
stream.Position = 0;
stream.Read(buffer, 0, buffer.Length);
baseStream.Write(buffer, 0, buffer.Length);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.