Read() private method

private Read ( ) : int
return int
コード例 #1
0
        /// <summary>
        /// Finds the delimiter by looking for the first line in the file and comparing chars
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static int FindDelimiter(this FileInfo source)
        {
            using (var stream = File.Open(source.FullName, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite))
            {
                using (var reader = new StreamReaderExtended(stream, Encoding.Default, true))
                {
                    if (reader.EndOfStream)
                        return -1;
                    do
                    {
                        var ch = (char)reader.Read();

                        // Note the following common line feed chars:
                        // \n - UNIX   \r\n - DOS   \r - Mac
                        switch (ch)
                        {
                            case '\r':
                                var next = (char)reader.Peek();
                                //with \n is WINDOWS delimiter. Otherwise mac
                                return next == '\n' ? 2 : 1;
                            case '\n':
                                return 1;
                        }
                    } while (!reader.EndOfStream);
                    return -1;
                }
            }
        }
コード例 #2
0
ファイル: FileInfoEx.cs プロジェクト: modulexcite/TailBlazer
        /// <summary>
        /// Finds the delimiter by looking for the first line in the file and comparing chars
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public static int FindDelimiter(this FileInfo source)
        {
            using (var stream = File.Open(source.FullName, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite))
            {
                using (var reader = new StreamReaderExtended(stream, Encoding.Default, true))
                {
                    if (reader.EndOfStream)
                    {
                        return(-1);
                    }
                    do
                    {
                        var ch = (char)reader.Read();

                        // Note the following common line feed chars:
                        // \n - UNIX   \r\n - DOS   \r - Mac
                        switch (ch)
                        {
                        case '\r':
                            var next = (char)reader.Peek();
                            //with \n is WINDOWS delimiter. Otherwise mac
                            return(next == '\n' ? 2 : 1);

                        case '\n':
                            return(1);
                        }
                    } while (!reader.EndOfStream);
                    return(-1);
                }
            }
        }