System.IO.StreamReader.DiscardBufferedData C# (CSharp) Method

DiscardBufferedData() public method

public DiscardBufferedData ( ) : void
return void
        public void DiscardBufferedData()
        {
            CheckAsyncTaskInProgress();

            _byteLen = 0;
            _charLen = 0;
            _charPos = 0;
            // in general we'd like to have an invariant that encoding isn't null. However,
            // for startup improvements for NullStreamReader, we want to delay load encoding. 
            if (_encoding != null)
            {
                _decoder = _encoding.GetDecoder();
            }
            _isBlocked = false;
        }

Usage Example

Example #1
0
        static void Main(string[] args)
        {
            string InputFileName = args[0];
            string Outputfolder = args[1];
            int OutputCount = int.Parse(args[2]);
            StreamReader reader = new StreamReader(InputFileName);

            //Count number of lines
            Console.WriteLine("Compute Lines..");
            int count = 0;
            while (!reader.EndOfStream)
            {
                reader.ReadLine();
                count++;
            }

            Console.WriteLine("Total lines: " + count);
            int chunkSize = count / OutputCount;
            reader.DiscardBufferedData();
            for (int i = 0; i < OutputCount && !reader.EndOfStream ; ++i)
            {
                Console.WriteLine("Writing {0} document...", i);
                StreamWriter writer = new StreamWriter(Outputfolder + "\\out" + i + ".tsv");
                for(int j = chunkSize * i; j < chunkSize*(i + 1) && !reader.EndOfStream; j++)
                {
                    writer.WriteLine(reader.ReadLine());
                }
                writer.Flush();
            }
            Console.Read();
        }
All Usage Examples Of System.IO.StreamReader::DiscardBufferedData