当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.DiscardBufferedData方法代码示例

本文整理汇总了C#中System.IO.StreamReader.DiscardBufferedData方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.DiscardBufferedData方法的具体用法?C# StreamReader.DiscardBufferedData怎么用?C# StreamReader.DiscardBufferedData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamReader的用法示例。


在下文中一共展示了StreamReader.DiscardBufferedData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LogFileMaxSize

        public void LogFileMaxSize( )
        {
            const int MaxSize = 32767;

            // Fill the log file
            const string alpabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            using ( StreamWriter writer = File.CreateText( LogFilePath ) )
            {
                for ( int i = 0; i < MaxSize / alpabet.Length; ++i )
                {
                    writer.Write( alpabet );
                }
                writer.Write( alpabet.Substring( 0, MaxSize % alpabet.Length ) );
            }

            const string logStr = "Hello World";
            TestLogger logger = new TestLogger();
            logger.Log( logStr );

            using ( FileStream stream = File.OpenRead( LogFilePath ) )
            {
                Assert.AreEqual( MaxSize, stream.Length );

                // Did we shift the existing contents?
                StreamReader reader = new StreamReader( stream );
                Assert.AreEqual( alpabet[logStr.Length], (char) reader.Read() );

                // Did we append the new log?
                stream.Position = MaxSize - logStr.Length;
                reader.DiscardBufferedData();
                Assert.AreEqual( logStr, reader.ReadToEnd() );
            }
        }
开发者ID:rajeshwarn,项目名称:RemoteDesktopPlus,代码行数:33,代码来源:LoggerTest.cs

示例2: EdiStream

 public EdiStream(Stream ediStream)
 {
     _streamReader = new StreamReader(ediStream);
     _interchangeContext = new InterchangeContext(_streamReader);
     ediStream.Position = 0;
     _streamReader.DiscardBufferedData();
 }
开发者ID:TheArPee,项目名称:EdifactFramework,代码行数:7,代码来源:EDIStream.cs

示例3: analyzeFile

        //analyze file and returns an array with all lines
        private string[] analyzeFile()
        {
            int counter = 0;
            string line;

            System.IO.StreamReader file = new System.IO.StreamReader(filePath.Text);
            var count = File.ReadLines(filePath.Text).Count();

            string[] dataEntries = new string[count];

            file.DiscardBufferedData();
            file.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
            file.BaseStream.Position = 0;

            //save all data entries to the array dataEntires
            while ((line = file.ReadLine()) != null)
            {
                dataEntries[counter] = line;
                counter++;
            }

            file.Close();

            return dataEntries;
        }
开发者ID:marcelo-spiezzi,项目名称:dataAnalysis,代码行数:26,代码来源:SIVMWindow.xaml.cs

示例4: BuildQuery

        public string BuildQuery(string WordListFile, int MaxWords)
        {
            string Query = null;

            FileStream FS = new FileStream(WordListFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            StreamReader SR = new StreamReader(FS);

            string text = SR.ReadToEnd();

            Regex RE = new Regex("\n", RegexOptions.Multiline);
            MatchCollection matches = RE.Matches(text);

            int numSearchTerms = random.Next(1, MaxWords);

            for (int i = 0; i < numSearchTerms; i++)
            {
                string temp = null;
                SR.DiscardBufferedData();
                SR.BaseStream.Position = random.Next(0, (int)SR.BaseStream.Length);
                temp = SR.ReadLine();
                temp = SR.ReadLine();

                Query += temp + " ";
            }

            SR.Close();
            FS.Close();

            return Query.Trim();
        }
开发者ID:norova,项目名称:haystack,代码行数:30,代码来源:haystack.cs

示例5: GetLastLineOfFile

        /// <summary>
        /// Return last line of a text file
        /// </summary>
        /// <param name="filePath">File path</param>
        /// <returns></returns>
        public static string GetLastLineOfFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
                throw new ArgumentNullException("filePath");

            if (!FileSystem.File.Exists(filePath))
                throw new FileNotFoundException("File not found: " + filePath);

            using (var sr = new StreamReader(filePath))
            {
                sr.BaseStream.Seek(0, SeekOrigin.End);

                long pos = -1;

                while (sr.BaseStream.Length + pos > 0)
                {
                    sr.BaseStream.Seek(pos, SeekOrigin.End);
                    var c = sr.Read();
                    sr.DiscardBufferedData();

                    if (c == Convert.ToInt32('\n'))
                    {
                        sr.BaseStream.Seek(pos + 1, SeekOrigin.End);
                        return sr.ReadToEnd();
                    }

                    --pos;
                }
            }

            return null;
        }
开发者ID:jv9,项目名称:Simplify,代码行数:37,代码来源:FileHelper.cs

示例6: EdiStream

 public EdiStream(Stream ediStream, string definitionsAssemblyName = null)
 {
     _streamReader = new StreamReader(ediStream);
     _interchangeContext = new InterchangeContext(_streamReader, definitionsAssemblyName);
     ediStream.Position = 0;
     _streamReader.DiscardBufferedData();
 }
开发者ID:khanfx,项目名称:ediFabric,代码行数:7,代码来源:EdiStream.cs

示例7: Main

        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();
        }
开发者ID:Yifei891031,项目名称:SplitFile,代码行数:31,代码来源:Program.cs

示例8: convertToField

        private static void convertToField(int spaceCount, StringBuilder fieldBuilder, StreamReader reader, ClassTemplate meta, int language_type)
        {
            if (fieldBuilder == null || reader == null || meta == null)
                return;
            //文件流回到开始的位置
            reader.DiscardBufferedData();
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            reader.BaseStream.Position = 0;

            string line;
            while ((line = reader.ReadLine()) != null)
            {

                line = findAndReplace(line, "%field_type%", meta.Field_type);
                line = findAndReplace(line, "%field_name%", meta.Field_name);
                line = findAndReplace(line, "%Field_name%", meta.Upper_field_name);
                if (line.IndexOf("%annotation%")!=-1&&string.IsNullOrEmpty(meta.Annotation))
                {
                    continue;
                }
                line = findAndReplace(line, "%annotation%", meta.Annotation);
                fieldBuilder.Append(getDesignatedSpace(spaceCount)).Append(line).Append("\r\n");

            }
        }
开发者ID:agan112,项目名称:convertSqlToEntity,代码行数:25,代码来源:Form1.cs

示例9: TilesetTableTest

 public TilesetTableTest()
 {
     var tilesetTableMemoryStream = FileStreams.TilesetTableStream();
     var tilesetTableStreamReader = new StreamReader(tilesetTableMemoryStream);
     tilesetTableStreamReader.DiscardBufferedData();
     tilesetTableMemoryStream.Position = 0;
     var tilesetTable = new TilesetTable(null, tilesetTableStreamReader);
 }
开发者ID:GoodAI,项目名称:BrainSimulator,代码行数:8,代码来源:TilesetTableTest.cs

示例10: Board

        public Board()
        {
            NumberOfSteps = 0;
            Rand = new Random();

            try
            {
                using (var board = new StreamReader("Board.txt"))
                {
                    var i = 0;
                    var j = 0;

                    while (board.EndOfStream != true)
                    {
                        board.ReadLine();
                        Boardx++;
                    }
                    board.DiscardBufferedData();
                    board.BaseStream.Position = 0;

                    BoardChars = new char[Boardx][];

                    while (board.EndOfStream != true && i < Boardx)
                    {
                        var line = board.ReadLine();
                        if (line != null)
                        {
                            var readLine = line.Trim('\uFEFF');
                            {
                                var array = readLine.ToCharArray();
                                ArrayLength = readLine.Length;
                                BoardChars[i] = new char[ArrayLength + 1];
                                while (j < ArrayLength)
                                {
                                    BoardChars[i][j] = array[j];
                                    BoardChars[i][j + 1] = '\n';
                                    //Write(BoardChars[i][j]);
                                    j++;
                                }
                                //WriteLine();
                            }
                        }
                        j = 0;
                        i++;
                    }
                    DisplayBoard();
                }
                //WriteLine("\nPress F12 to quit.");
            }
            catch (FileNotFoundException e)
            {
                WriteLine("Attention ! Fichier : " + e.Source + " introuvable !");
            }
            catch (DirectoryNotFoundException e)
            {
                WriteLine("Attention ! Dossier : " + e.Source + " introuvable !");
            }
        }
开发者ID:AdrienTODA,项目名称:RPG,代码行数:58,代码来源:Board.cs

示例11: LoadTextResource

 public static string LoadTextResource(Assembly assembly, string sResourceName)
 {
     string sReturn = "";
     using (var sr = new StreamReader(assembly.GetManifestResourceStream(sResourceName)))
     {
         sReturn = sr.ReadToEnd();
         sr.DiscardBufferedData();
         sr.Close();
     }
     return sReturn;
 }
开发者ID:pdwetz,项目名称:KindleBookHelper,代码行数:11,代码来源:FileUtilities.cs

示例12: getBitmapsInfoFromDirectory

        public static SeismicBitmapInfo[] getBitmapsInfoFromDirectory()
        {
            var applicationDirectory = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "Resources\\";

            //will return a list of seismic data
            string[] jpgFiles = Directory.GetFiles(applicationDirectory, imageJPGExtension);
            string[] dataFiles = Directory.GetFiles(applicationDirectory, dataExtension);

            if (dataFiles.Length != 1 || jpgFiles.Length == 0)
                return null;

            StreamReader dataReader = new StreamReader(dataFiles[0]);
            int lineCount = 0;
            while (dataReader.ReadLine() != null)
                lineCount++;

            dataReader.BaseStream.Position = 0;
            dataReader.DiscardBufferedData();

            if (lineCount % 3 != 0)
                return null;//The number of lines must be a multiple of 3, because 1 piece of "data" requires 3 lines, line name, 2 lat/long points

            int numberOfSeismicImages = lineCount / 3;

            if (numberOfSeismicImages != jpgFiles.Length)
                return null;

            List<SeismicBitmapInfo> bitmapInfoCollection = new List<SeismicBitmapInfo>();
            string[] dataStrings = new string[3];
            SeismicBitmapInfo newinfo;
            for (int i = 0; i < numberOfSeismicImages; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    dataStrings[j] = dataReader.ReadLine();
                }

                string lineFileName = getLineFileFromString(applicationDirectory, dataStrings[0]);
                if (!jpgFiles.Contains(lineFileName))
                    continue;//You only create and populate info for lines that both exist in the data file, and have corresponding image file

                newinfo = new SeismicBitmapInfo();
                newinfo.line = new LineSegment(getLatLongPointFromString(dataStrings[1]), getLatLongPointFromString(dataStrings[2]));
                newinfo.bitmapName = lineFileName;
                newinfo.bitmapImage = new BitmapImage(new Uri(lineFileName, UriKind.Relative));
                newinfo.lineNumber = getLineNumberFromString(dataStrings[0]);
                //bitmapInfoCollection.Add(newinfo);
                insertSeismicInfoIntoList(bitmapInfoCollection, newinfo);
            }

            //bitmapInfoCollection.Reverse();

            return bitmapInfoCollection.ToArray();
        }
开发者ID:ase-lab,项目名称:Skyhunter,代码行数:54,代码来源:FileUtilities.cs

示例13: Main

        static void Main(string[] args)
        {
            StreamReader inputFile;
            StreamReader tranInputFile;

            char[] code = new char[3];
            string tranCode;
            string tCode;

            string[] fileNameSuffix = { "1", "2", "3" };

            StreamWriter logSession = new StreamWriter("./../../../LogSession.txt",true);
            for (int i = 0; i < fileNameSuffix.Length; i++)
            {

                inputFile = new StreamReader("./../../../" + "MainData" + fileNameSuffix[i] + ".txt");
                tranInputFile = new StreamReader("./../../../" + "TransData" + fileNameSuffix[i] + ".txt");
                CodeIndex index = new CodeIndex(fileNameSuffix[i]);
                logSession.WriteLine("==============");
                logSession.WriteLine("PROCESSING TransData " + fileNameSuffix[i].ToString());
                while (!tranInputFile.EndOfStream)
                {
                    string[] tranLine = tranInputFile.ReadLine().Split(' ');

                    tranCode = tranLine[0];  //QC
                    tCode = (tranLine[1]);  //***

                    short DRP = index.QueryByCode(tCode);

                    if (DRP == -1)
                    {

                    }
                    else
                    {
                        inputFile.DiscardBufferedData();
                        inputFile.BaseStream.Seek(25 * (DRP - 1), SeekOrigin.Begin);
                        logSession.WriteLine(tranCode + " " + tCode);
                        logSession.WriteLine(">> "+ inputFile.ReadLine());
                        logSession.WriteLine("[# of nodes read: " + index.NodeCount.ToString() + "]");
                    }
                }

                index.FinishUp();
                inputFile.Close();
                tranInputFile.Close();

            }

            logSession.Close();
        }
开发者ID:Zaskeu,项目名称:WMU-School-Project,代码行数:51,代码来源:TempUserApp.cs

示例14: ReadOutput

        static String ReadOutput(StreamReader reader, bool print = true)
        {
            StringBuilder str = new StringBuilder();
            reader.DiscardBufferedData();
            while (reader.Peek() != -1)
            {
                str.Append((char)reader.Read());
            }
            str.Append("\n");

            if(print)
                Console.WriteLine("engine << " + str.ToString());
            
            return str.ToString().Trim();
        }
开发者ID:GMDIT,项目名称:LeapChess,代码行数:15,代码来源:Program.cs

示例15: ReadLines

 public IEnumerable<string> ReadLines(FileInfo sourceFile)
 {
     using (var reader = new StreamReader(sourceFile.FullName))
     {
         while (true)
         {
             if (reader.EndOfStream)
             {
                 reader.BaseStream.Position = 0;
                 reader.DiscardBufferedData();
             }
             yield return reader.ReadLine();
         }
     }
 }
开发者ID:ddpruitt,项目名称:Rx-Examples,代码行数:15,代码来源:RostockMax.cs


注:本文中的System.IO.StreamReader.DiscardBufferedData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。