public void WriterThreadMethod(object o) { ByteBufferStream p = (ByteBufferStream)o; byte[] writeBlock = new byte[8 * 1024]; for (int i = 0; i < 70; i++) { p.Write(writeBlock, 0, writeBlock.Length); Interlocked.Add(ref dataWritten, writeBlock.Length); } }
public void CopyTo() { var byteBuffer = Unpooled.Buffer(4096); var bufferStream = new ByteBufferStream(byteBuffer, true); var text = "Hello World"; var bytes = Encoding.UTF8.GetBytes(text); bufferStream.Write(bytes, 0, bytes.Length); Assert.Equal(bytes.Length, bufferStream.Length); var ms = new MemoryStream(); bufferStream.CopyTo(ms); ms.Position = 0; Assert.Equal(text, Encoding.UTF8.GetString(ms.ToArray())); bufferStream.Close(); }
public void TestSerialWrites() { var str = new ByteBufferStream(16 * 1024); byte[] writeBlock = new byte[8 * 1024]; byte[] readBlock = new byte[7 * 1024]; int detritusSize = 0; for (int i = 0; i < 73; i++) { str.Write(writeBlock, 0, writeBlock.Length); detritusSize += writeBlock.Length; Assert.IsTrue(detritusSize == str.BytesCurrentlyInStream, "expect size ({0}) does not match actual size ({1})", detritusSize, str.BytesCurrentlyInStream); detritusSize -= str.Read(readBlock, 0, readBlock.Length); Assert.IsTrue(detritusSize == str.BytesCurrentlyInStream, "expect size ({0}) does not match actual size ({1})", detritusSize, str.BytesCurrentlyInStream); while (detritusSize >= readBlock.Length) { detritusSize -= str.Read(readBlock, 0, readBlock.Length); Assert.IsTrue(detritusSize == str.BytesCurrentlyInStream, "expect size ({0}) does not match actual size ({1})", detritusSize, str.BytesCurrentlyInStream); } } Assert.IsTrue(detritusSize == str.BytesCurrentlyInStream, "expect size ({0}) does not match actual size ({1})", detritusSize, str.BytesCurrentlyInStream); }