Ejemplo n.º 1
0
        public static Stream GetAppropriateStream(PeekStream peekStream)
        {
            var header = peekStream.PeekBytes(NumHeaderBytes);
            var compressionAlgorithm = IdentifyCompressionAlgorithm(header);

            return(GetAppropriateStream(peekStream, compressionAlgorithm));
        }
Ejemplo n.º 2
0
        public PeekStreamTests()
        {
            var memoryStream = new MemoryStream();

            using (var writer = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true)) writer.WriteLine("testing");
            memoryStream.Position = 0;
            _peekStream           = new PeekStream(memoryStream);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <para>Creates and returns a new peek stream linked to this stream. Reading from the returned stream allows
        /// peeking at the bytes ahead of the current position in this stream, without changing the outcome of future
        /// calls to any methods on this stream.</para>
        /// <para>The returned stream must be disposed of when done, since outstanding undisposed peek streams have a slight
        /// performance impact on most operations on this peekable stream.</para>
        /// <para>See Remarks on <see cref="PeekableStream"/> for more info.</para>
        /// </summary>
        public PeekStream GetPeekStream()
        {
            var peek = new PeekStream(this);

            peek._buffer = _buffers.First;
            peek._offset = _offset;
            _peeks.Add(peek);
            return(peek);
        }
Ejemplo n.º 4
0
        private LiteVcfReader GetVcfReader()
        {
            var useStdInput = ConfigurationSettings.VcfPath == "-";

            var peekStream =
                new PeekStream(useStdInput
                    ? Console.OpenStandardInput()
                    : FileUtilities.GetReadStream(ConfigurationSettings.VcfPath));

            return(new LiteVcfReader(GZipUtilities.GetAppropriateStream(peekStream)));
        }
Ejemplo n.º 5
0
        public static IVcfReader GetVcfReader(string vcfPath, IDictionary <string, IChromosome> chromosomeDictionary,
                                              IRefMinorProvider refMinorProvider, bool verboseTranscript, IRecomposer recomposer)
        {
            var useStdInput = vcfPath == "-";

            var peekStream =
                new PeekStream(useStdInput
                        ? Console.OpenStandardInput()
                        : GZipUtilities.GetAppropriateReadStream(vcfPath));

            return(new VcfReader(peekStream, chromosomeDictionary, refMinorProvider, verboseTranscript, recomposer));
        }
Ejemplo n.º 6
0
        public void Should_ThrowException_Constructor_InvalidBufferSize()
        {
            var memoryStream = new MemoryStream(new byte[50]);

            Assert.Throws <ArgumentOutOfRangeException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var peekStream = new PeekStream(memoryStream, 0);
            });

            Assert.Throws <ArgumentOutOfRangeException>(delegate
            {
                // ReSharper disable once UnusedVariable
                var peekStream = new PeekStream(memoryStream, -1);
            });
        }
Ejemplo n.º 7
0
        public void GetAppropriateStream_Handle_PeekStream()
        {
            string observedString;

            using (var ms = new MemoryStream())
            {
                using (var writer = new BinaryWriter(new BlockGZipStream(ms, CompressionMode.Compress, true)))
                {
                    writer.Write(ExpectedString);
                }

                ms.Position = 0;

                using (var peekStream = new PeekStream(ms))
                    using (var reader = new BinaryReader(GZipUtilities.GetAppropriateStream(peekStream)))
                    {
                        observedString = reader.ReadString();
                    }
            }

            Assert.Equal(ExpectedString, observedString);
        }
Ejemplo n.º 8
0
        public void GetAppropriateStream_PeekStream_WithTextFile()
        {
            string observedString;

            using (var ms = new MemoryStream())
            {
                using (var writer = new StreamWriter(ms, Encoding.UTF8, 1024, true))
                {
                    writer.WriteLine(ExpectedString);
                }

                ms.Position = 0;

                using (var peekStream = new PeekStream(ms))
                    using (var reader = new StreamReader(GZipUtilities.GetAppropriateStream(peekStream)))
                    {
                        observedString = reader.ReadLine();
                    }
            }

            Assert.Equal(ExpectedString, observedString);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilteredStream{T}"/> class.
 /// </summary>
 /// <param name="underlying">The underlying stream this one reads from.</param>
 /// <param name="predicate">The predicate used for filtering.</param>
 public FilteredStream(IStream <T> underlying, Predicate <T> predicate)
 {
     this.underlying = new PeekStream <T>(underlying);
     this.Predicate  = predicate;
     this.UpdatePeek();
 }
Ejemplo n.º 10
0
 public HessianReader(Stream input, bool closeInput)
 {
     this.input = new PeekStream(input);
     this.ownsStream = closeInput;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// <para>Creates and returns a new peek stream linked to this stream. Reading from the returned stream allows
 /// peeking at the bytes ahead of the current position in this stream, without changing the outcome of future
 /// calls to any methods on this stream.</para>
 /// <para>The returned stream must be disposed of when done, since outstanding undisposed peek streams have a slight
 /// performance impact on most operations on this peekable stream.</para>
 /// <para>See Remarks on <see cref="PeekableStream"/> for more info.</para>
 /// </summary>
 public PeekStream GetPeekStream()
 {
     var peek = new PeekStream(this);
     peek._buffer = _buffers.First;
     peek._offset = _offset;
     _peeks.Add(peek);
     return peek;
 }