コード例 #1
0
        private static FileHeader GetHeader(BlockStream blockStream, out DemoCustomHeader customHeader)
        {
            var headerType = FileHeader.GetHeader(0, GenomeAssembly.Unknown, new DemoCustomHeader(new BlockStream.BlockPosition()));
            var header     = (FileHeader)blockStream.ReadHeader(headerType);

            customHeader = header.Custom as DemoCustomHeader;
            return(header);
        }
コード例 #2
0
        public void ReadAndWrite()
        {
            string expectedString = GetRandomString(Block.Size + 10000);

            var customHeader = new DemoCustomHeader(new BlockStream.BlockPosition());
            var header       = new FileHeader(CacheConstants.Identifier, CacheConstants.SchemaVersion,
                                              CacheConstants.DataVersion, TranscriptDataSource.Ensembl, NumTicks, ExpectedGenomeAssembly, customHeader);

            using (var ms = new MemoryStream())
            {
                WriteBlockStream(Qlz, header, customHeader, ms, expectedString);
                ms.Seek(0, SeekOrigin.Begin);
                ReadFromBlockStream(Qlz, ms, expectedString);
            }
        }
コード例 #3
0
        private static void WriteBlockStream(ICompressionAlgorithm compressionAlgorithm, IFileHeader header,
                                             DemoCustomHeader customHeader, MemoryStream ms, string s)
        {
            using (var blockStream = new BlockStream(compressionAlgorithm, ms, CompressionMode.Compress, true))
                using (var writer = new ExtendedBinaryWriter(blockStream))
                {
                    CheckReadException(blockStream);

                    blockStream.WriteHeader(header);

                    var bp = new BlockStream.BlockPosition();

                    // detect that we have written a block
                    blockStream.GetBlockPosition(bp);
                    int beforeBlockId = bp.Id;

                    writer.WriteOptAscii(s);

                    blockStream.GetBlockPosition(bp);
                    int afterBlockId = bp.Id;

                    Assert.NotEqual(beforeBlockId, afterBlockId);

                    // here we write a test string that won't invoke a new block
                    blockStream.GetBlockPosition(customHeader.DemoPosition);
                    beforeBlockId = customHeader.DemoPosition.Id;

                    writer.WriteOptAscii(SmallString);

                    blockStream.GetBlockPosition(bp);
                    afterBlockId = customHeader.DemoPosition.Id;

                    Assert.Equal(beforeBlockId, afterBlockId);
                    Assert.Equal(customHeader.DemoPosition.FileOffset, blockStream.Position);

                    blockStream.Flush();

                    // this will be flushed during dispose
                    writer.WriteOptAscii(FinalString);
                }
        }