Beispiel #1
0
        public void TestStreamToTextOtherStream()
        {
            var stream1 = new StorageStream(new MemoryStorage());

            stream1.Write(Encoding.Default.GetBytes("Hello world"), 0, 11);
            stream1.Seek(0, SeekOrigin.Begin);
            Assert.AreEqual("Hello world", stream1.ToText());
        }
Beispiel #2
0
        public void TestStreamToTextLarage()
        {
            var stream1 = new StorageStream(new MemoryStorage());
            var builder = new StringBuilder();

            for (var i = 0; i < (ThreadStatic.Buffer.Length / 10) + 1; i++)
            {
                stream1.Write(Encoding.Default.GetBytes("1234567890"), 0, 10);
                builder.Append("1234567890");
            }
            stream1.Seek(0, SeekOrigin.Begin);
            Assert.AreEqual(builder.ToString(), stream1.ToText());
        }
Beispiel #3
0
        public void TestChineseText()
        {
            var stream1 = new StorageStream(new MemoryStorage());
            var builder = new StringBuilder();

            for (var i = 0; i < (ThreadStatic.Buffer.Length / 10) + 1; i++)
            {
                var data = Encoding.UTF8.GetBytes("12中文34测试的5这是67890");
                stream1.Write(data, 0, data.Length);
                builder.Append("12中文34测试的5这是67890");
            }
            stream1.Seek(0, SeekOrigin.Begin);
            Assert.AreEqual(builder.ToString(), stream1.ToText());
        }
Beispiel #4
0
        public PersistentBlock ReadBlock(string primaryKey)
        {
            if (BlockInfoByPrimaryKey.TryGetValue(primaryKey, out var info))
            {
                var block = new PersistentBlock();

                StorageStream.Seek(info.Offset, SeekOrigin.Begin);
                var reader = new BinaryReader(StorageStream);

                block.Read(reader);

                return(block);
            }

            throw new NotSupportedException("primary key not found in backup storage");
        }