/// <summary> /// Initializes a new instance of the <see cref="EndianBinaryWriter"/> class /// with the given bit converter, writing to the given stream, using the given encoding. /// </summary> /// <param name="endianness">Endianness to use when writing data</param> /// <param name="stream">Stream to write data to</param> /// <param name="encoding"> /// Encoding to use when writing character data /// </param> public EndianBinaryWriter(Endianness endianness, Stream stream, Encoding encoding) { var bitConverter = EndianBitConverter.GetConverter(endianness); // TODO: Use Guard if (bitConverter == null) { throw new ArgumentNullException("bitConverter"); } if (stream == null) { throw new ArgumentNullException("stream"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } if (!stream.CanWrite) { throw new ArgumentException("Stream isn't writable", "stream"); } this.BaseStream = stream; this.BitConverter = bitConverter; this.Encoding = encoding; }
/// <summary> /// Initializes a new instance of the <see cref="EndianBinaryWriter"/> class /// with the given bit converter, writing to the given stream, using the given encoding. /// </summary> /// <param name="endianness">Endianness to use when writing data</param> /// <param name="stream">Stream to write data to</param> /// <param name="encoding"> /// Encoding to use when writing character data /// </param> public EndianBinaryWriter(Endianness endianness, Stream stream, Encoding encoding) { Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(encoding)); Guard.IsTrue(stream.CanWrite, nameof(stream), "Stream isn't writable"); this.BaseStream = stream; this.BitConverter = EndianBitConverter.GetConverter(endianness); this.Encoding = encoding; }
/// <summary> /// Initializes a new instance of the <see cref="EndianBinaryReader"/> class. /// Constructs a new binary reader with the given bit converter, reading /// to the given stream, using the given encoding. /// </summary> /// <param name="endianness">Endianness to use when reading data</param> /// <param name="stream">Stream to read data from</param> /// <param name="encoding">Encoding to use when reading character data</param> public EndianBinaryReader(Endianness endianness, Stream stream, Encoding encoding) { Guard.NotNull(stream, nameof(stream)); Guard.NotNull(encoding, nameof(encoding)); Guard.IsTrue(stream.CanRead, nameof(stream), "Stream isn't readable."); this.BaseStream = stream; this.BitConverter = EndianBitConverter.GetConverter(endianness); this.Encoding = encoding; this.decoder = encoding.GetDecoder(); this.minBytesPerChar = 1; if (encoding is UnicodeEncoding) { this.minBytesPerChar = 2; } }