示例#1
0
        public static long GetCharpos(this StreamReader s)
        {
            if (SystemUtils.IsLinux) // in mono
            {
                Int32 charpos = (Int32)s.GetType().InvokeMember("pos",
                                                                BindingFlags.DeclaredOnly |
                                                                BindingFlags.Public | BindingFlags.NonPublic |
                                                                BindingFlags.Instance | BindingFlags.GetField
                                                                , null, s, null);

                Int32 charlen = (Int32)s.GetType().InvokeMember("decoded_count",
                                                                BindingFlags.DeclaredOnly |
                                                                BindingFlags.Public | BindingFlags.NonPublic |
                                                                BindingFlags.Instance | BindingFlags.GetField
                                                                , null, s, null);

                return(s.BaseStream.Position - charlen + charpos);
            }
            else
            {
                Int32 charpos = (Int32)s.GetType().InvokeMember("charPos",
                                                                BindingFlags.DeclaredOnly |
                                                                BindingFlags.Public | BindingFlags.NonPublic |
                                                                BindingFlags.Instance | BindingFlags.GetField
                                                                , null, s, null);

                Int32 charlen = (Int32)s.GetType().InvokeMember("charLen",
                                                                BindingFlags.DeclaredOnly |
                                                                BindingFlags.Public | BindingFlags.NonPublic |
                                                                BindingFlags.Instance | BindingFlags.GetField
                                                                , null, s, null);

                return(s.BaseStream.Position - charlen + charpos);
            }
        }
        private static long GetCharposMono3(StreamReader s)
        {
            Int32 charpos = (Int32)s.GetType().InvokeMember("pos",
                                                            BindingFlags.DeclaredOnly |
                                                            BindingFlags.Public | BindingFlags.NonPublic |
                                                            BindingFlags.Instance | BindingFlags.GetField
                                                            , null, s, null);

            Int32 charlen = (Int32)s.GetType().InvokeMember("decoded_count",
                                                            BindingFlags.DeclaredOnly |
                                                            BindingFlags.Public | BindingFlags.NonPublic |
                                                            BindingFlags.Instance | BindingFlags.GetField
                                                            , null, s, null);

            return(s.BaseStream.Position - charlen + charpos);
        }
示例#3
0
        public void leeArchivo()
        {
            string ubicacion;
            try
            {
                Console.WriteLine("Dame la ubicacion de el arcihvo");
                ubicacion = Console.ReadLine();

                StreamReader objReader = new StreamReader(ubicacion);
                objReader.GetType();

                string sLine= objReader.ReadLine();
                ArrayList arrText = new ArrayList();

                    while (sLine != null)
                    {
                        agregaResisgtro(sLine);
                        sLine = objReader.ReadLine();
                    }
                     objReader.Close();

            }
            catch(Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Cerrando la lectura.");
            }
        }
示例#4
0
    private static long GetCharposMono3(StreamReader s)
    {
      Int32 charpos = (Int32)s.GetType().InvokeMember("pos",
      BindingFlags.DeclaredOnly |
      BindingFlags.Public | BindingFlags.NonPublic |
      BindingFlags.Instance | BindingFlags.GetField
      , null, s, null);

      Int32 charlen = (Int32)s.GetType().InvokeMember("decoded_count",
      BindingFlags.DeclaredOnly |
      BindingFlags.Public | BindingFlags.NonPublic |
      BindingFlags.Instance | BindingFlags.GetField
      , null, s, null);

      return s.BaseStream.Position - charlen + charpos;
    }
        private static long GetStreamReaderPreambleSize(StreamReader sr)
        {
            if (_streamReaderPreambleProperty == null)
            {
                _streamReaderPreambleProperty = sr.GetType()
                                                  .GetProperty("Preamble_Prop",
                                                               BindingFlags.Instance | BindingFlags.NonPublic);
            }

            return ((byte[])_streamReaderPreambleProperty.GetValue(sr)).Length;
        }
示例#6
0
文件: Readers.cs 项目: umoder/essence
        public long GetActualPosition(StreamReader reader)
        {
            // The current buffer of decoded characters
            char[] charBuffer = (char[])reader.GetType().InvokeMember("charBuffer"
                , System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField
                , null, reader, null);

            // The current position in the buffer of decoded characters
            int charPos = (int)reader.GetType().InvokeMember("charPos"
                , System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField
                , null, reader, null);

            // The number of bytes that the already-read characters need when encoded.
            int numReadBytes = reader.CurrentEncoding.GetByteCount(charBuffer, 0, charPos);

            // The number of encoded bytes that are in the current buffer
            int byteLen = (int)reader.GetType().InvokeMember("byteLen"
                , System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField
                , null, reader, null);

            return reader.BaseStream.Position - byteLen + numReadBytes;
        }
        private static int GetStreamReaderBufferPos(StreamReader sr)
        {
            if (_streamReaderBufferPositionProperty == null)
            {
                _streamReaderBufferPositionProperty = sr.GetType()
                                                        .GetProperty("CharPos_Prop",
                                                                     BindingFlags.Instance | BindingFlags.NonPublic);
            }

            return (int)_streamReaderBufferPositionProperty.GetValue(sr);
        }
        private static long GetStreamReaderBufferLength(StreamReader sr)
        {
            if (_streamReaderByteLenProperty == null)
            {
                _streamReaderByteLenProperty = sr.GetType()
                                                 .GetProperty("ByteLen_Prop",
                                                              BindingFlags.Instance | BindingFlags.NonPublic);
            }

            return (int)_streamReaderByteLenProperty.GetValue(sr);
        }
示例#9
0
        // Get the actual file position from a buffered StreamReader object. From: https://stackoverflow.com/a/17457085
        public static long GetActualPosition(System.IO.StreamReader reader)
        {
            System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField;

            // The current buffer of decoded characters
            char[] charBuffer = (char[])reader.GetType().InvokeMember("charBuffer", flags, null, reader, null);

            // The index of the next char to be read from charBuffer
            int charPos = (int)reader.GetType().InvokeMember("charPos", flags, null, reader, null);

            // The number of decoded chars presently used in charBuffer
            int charLen = (int)reader.GetType().InvokeMember("charLen", flags, null, reader, null);

            // The current buffer of read bytes (byteBuffer.Length = 1024; this is critical).
            byte[] byteBuffer = (byte[])reader.GetType().InvokeMember("byteBuffer", flags, null, reader, null);

            // The number of bytes read while advancing reader.BaseStream.Position to (re)fill charBuffer
            int byteLen = (int)reader.GetType().InvokeMember("byteLen", flags, null, reader, null);

            // The number of bytes the remaining chars use in the original encoding.
            int numBytesLeft = reader.CurrentEncoding.GetByteCount(charBuffer, charPos, charLen - charPos);

            // For variable-byte encodings, deal with partial chars at the end of the buffer
            int numFragments = 0;

            if (byteLen > 0 && !reader.CurrentEncoding.IsSingleByte)
            {
                if (reader.CurrentEncoding.CodePage == 65001) // UTF-8
                {
                    byte byteCountMask = 0;
                    while ((byteBuffer[byteLen - numFragments - 1] >> 6) == 2) // if the byte is "10xx xxxx", it's a continuation-byte
                    {
                        byteCountMask |= (byte)(1 << ++numFragments);          // count bytes & build the "complete char" mask
                    }
                    if ((byteBuffer[byteLen - numFragments - 1] >> 6) == 3)    // if the byte is "11xx xxxx", it starts a multi-byte char.
                    {
                        byteCountMask |= (byte)(1 << ++numFragments);          // count bytes & build the "complete char" mask
                    }
                    // see if we found as many bytes as the leading-byte says to expect
                    if (numFragments > 1 && ((byteBuffer[byteLen - numFragments] >> 7 - numFragments) == byteCountMask))
                    {
                        numFragments = 0; // no partial-char in the byte-buffer to account for
                    }
                }
                else if (reader.CurrentEncoding.CodePage == 1200) // UTF-16LE
                {
                    if (byteBuffer[byteLen - 1] >= 0xd8)          // high-surrogate
                    {
                        numFragments = 2;                         // account for the partial character
                    }
                }
                else if (reader.CurrentEncoding.CodePage == 1201) // UTF-16BE
                {
                    if (byteBuffer[byteLen - 2] >= 0xd8)          // high-surrogate
                    {
                        numFragments = 2;                         // account for the partial character
                    }
                }
            }
            return(reader.BaseStream.Position - numBytesLeft - numFragments);
        }