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


C# Encoding.GetDecoder方法代码示例

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


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

示例1: EndianReader

        public EndianReader(Stream input, Endianness endianess, Encoding encoding, bool leaveOpen)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }
            if (!input.CanRead)
                throw new ArgumentException("Can't read from the output stream", nameof(input));
            Contract.EndContractBlock();

            BaseStream = input;
            decoder = encoding.GetDecoder();
            maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize);
            var minBufferSize = encoding.GetMaxByteCount(1);  // max bytes per one char
            if (minBufferSize < 16)
                minBufferSize = 16;
            buffer = new byte[minBufferSize];
            // m_charBuffer and m_charBytes will be left null.

            // For Encodings that always use 2 bytes per char (or more), 
            // special case them here to make Read() & Peek() faster.
            use2BytesPerChar = encoding is UnicodeEncoding;
            this.leaveOpen = leaveOpen;

            Endianness = endianess;
            resolvedEndianess = EndianessHelper.Resolve(endianess);

            Contract.Assert(decoder != null, "[EndianReader.ctor]m_decoder!=null");
        }
开发者ID:vbfox,项目名称:U2FExperiments,代码行数:33,代码来源:EndianReader.cs

示例2: BinaryReader

 public BinaryReader(Stream input, Encoding encoding)
 {
     if (input == null)
     {
         throw new ArgumentNullException("input");
     }
     if (encoding == null)
     {
         throw new ArgumentNullException("encoding");
     }
     if (!input.CanRead)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable"));
     }
     this.m_stream = input;
     this.m_decoder = encoding.GetDecoder();
     this.m_maxCharsSize = encoding.GetMaxCharCount(0x80);
     int maxByteCount = encoding.GetMaxByteCount(1);
     if (maxByteCount < 0x10)
     {
         maxByteCount = 0x10;
     }
     this.m_buffer = new byte[maxByteCount];
     this.m_charBuffer = null;
     this.m_charBytes = null;
     this.m_2BytesPerChar = encoding is UnicodeEncoding;
     this.m_isMemoryStream = this.m_stream.GetType() == typeof(MemoryStream);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:BinaryReader.cs

示例3: EndianBinaryReader

 public EndianBinaryReader(EndianBitConverter bitConverter, Stream stream, System.Text.Encoding encoding)
 {
     this.disposed = false;
     this.buffer = new byte[0x10];
     this.charBuffer = new char[1];
     if (bitConverter == null)
     {
         throw new ArgumentNullException("bitConverter");
     }
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (encoding == null)
     {
         throw new ArgumentNullException("encoding");
     }
     if (!stream.CanRead)
     {
         throw new ArgumentException("Stream isn't writable", "stream");
     }
     this.stream = stream;
     this.bitConverter = bitConverter;
     this.encoding = encoding;
     this.decoder = encoding.GetDecoder();
     this.minBytesPerChar = 1;
     if (encoding is UnicodeEncoding)
     {
         this.minBytesPerChar = 2;
     }
 }
开发者ID:BGCX261,项目名称:znqq-svn-to-git,代码行数:31,代码来源:EndianBinaryReader.cs

示例4: Init

        private void Init(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen)
        {
            _stream = stream;
            _encoding = encoding;
            _decoder = encoding.GetDecoder();
            if (bufferSize < MinBufferSize)
            {
                bufferSize = MinBufferSize;
            }

            _byteBuffer = new byte[bufferSize];
            _maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize);
            _charBuffer = new char[_maxCharsPerBuffer];
            _byteLen = 0;
            _bytePos = 0;
            _detectEncoding = detectEncodingFromByteOrderMarks;

            // Encoding.GetPreamble() always allocates and returns a new byte[] array for
            // encodings that have a preamble.
            // We can avoid repeated allocations for the default and commonly used Encoding.UTF8
            // encoding by using our own private cached instance of the UTF8 preamble.
            // We specifically look for Encoding.UTF8 because we know it has a preamble,
            // whereas other instances of UTF8Encoding may not have a preamble enabled, and
            // there's no public way to tell if the preamble is enabled for an instance other
            // than calling GetPreamble(), which we're trying to avoid.
            // This means that other instances of UTF8Encoding are excluded from this optimization.
            _preamble = object.ReferenceEquals(encoding, Encoding.UTF8) ?
                (s_utf8Preamble ?? (s_utf8Preamble = encoding.GetPreamble())) :
                encoding.GetPreamble();

            _checkPreamble = (_preamble.Length > 0);
            _isBlocked = false;
            _closable = !leaveOpen;
        }
开发者ID:antiufo,项目名称:Shaman.ValueString,代码行数:34,代码来源:ValueStringStreamReader.cs

示例5: ContentReader

 public ContentReader(Stream stream, long length, Encoding encoding = null) {
     _stream = stream;
     _length = length;
     if (encoding != null) {
         _decoder = encoding.GetDecoder();
     }
 }
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:7,代码来源:ContentReader.cs

示例6: CFile

 /// <summary>
 /// Create new C file access
 /// </summary>
 public CFile(Stream stream, Encoding encoding = null)
 {
     this._Stream = stream;
     EOF = _Stream == null;
     this._Encoding = encoding ?? Encoding.GetEncoding("Windows-1252");
     this._Decoder = _Encoding.GetDecoder();
 }
开发者ID:thenuts,项目名称:SwissEphNet,代码行数:10,代码来源:CFile.cs

示例7: HttpRequestStreamReader

        public HttpRequestStreamReader(Stream stream, Encoding encoding, int bufferSize)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanRead)
            {
                throw new ArgumentException(Resources.HttpRequestStreamReader_StreamNotReadable, nameof(stream));
            }

            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            _stream = stream;
            _encoding = encoding;
            _decoder = encoding.GetDecoder();

            if (bufferSize < MinBufferSize)
            {
                bufferSize = MinBufferSize;
            }

            _byteBufferSize = bufferSize;
            _byteBuffer = new byte[bufferSize];
            var maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize);
            _charBuffer = new char[maxCharsPerBuffer];
        }
开发者ID:phinq19,项目名称:git_example,代码行数:31,代码来源:HttpRequestStreamReader.cs

示例8: EndianBinaryReader

        /// <summary>
        /// Constructs a new binary reader with the given bit converter, reading
        /// to the given stream, using the given encoding.
        /// </summary>
        /// <param name="bitConverter">Converter to use when reading data</param>
        /// <param name="stream">Stream to read data from</param>
        /// <param name="encoding">Encoding to use when reading character data</param>
        public EndianBinaryReader(EndianBitConverter bitConverter, Stream stream, Encoding encoding)
        {
            if (bitConverter == null)
            {
                throw new ArgumentNullException("bitConverter");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("Stream isn't writable", "stream");
            }
            this.stream = stream;
            this.bitConverter = bitConverter;
            this.encoding = encoding;
            this.decoder = encoding.GetDecoder();
            this.minBytesPerChar = 1;

            if (encoding is UnicodeEncoding)
            {
                minBytesPerChar = 2;
            }
        }
开发者ID:cornelius90,项目名称:InnovatorAdmin,代码行数:36,代码来源:EndianBinaryReader.cs

示例9: BinaryReader

        public BinaryReader(Stream input, Encoding encoding, bool leaveOpen) {
            if (input==null) {
                throw new ArgumentNullException(nameof(input));
            }
            if (encoding==null) {
                throw new ArgumentNullException(nameof(encoding));
            }
            if (!input.CanRead)
                throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable"));
            Contract.EndContractBlock();
            m_stream = input;
            m_decoder = encoding.GetDecoder();
            m_maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize);
            int minBufferSize = encoding.GetMaxByteCount(1);  // max bytes per one char
            if (minBufferSize < 16) 
                minBufferSize = 16;
            m_buffer = new byte[minBufferSize];
            // m_charBuffer and m_charBytes will be left null.

            // For Encodings that always use 2 bytes per char (or more), 
            // special case them here to make Read() & Peek() faster.
            m_2BytesPerChar = encoding is UnicodeEncoding;
            // check if BinaryReader is based on MemoryStream, and keep this for it's life
            // we cannot use "as" operator, since derived classes are not allowed
            m_isMemoryStream = (m_stream.GetType() == typeof(MemoryStream));
            m_leaveOpen = leaveOpen;

            Contract.Assert(m_decoder!=null, "[BinaryReader.ctor]m_decoder!=null");
        }
开发者ID:JonHanna,项目名称:coreclr,代码行数:29,代码来源:BinaryReader.cs

示例10: PositionedStreamReader

 public PositionedStreamReader(Stream stream, Encoding encoding)
 {
     this.stream = stream;
     this.encoding = encoding;
     decoder = encoding.GetDecoder();
     bufferpos = 0;
     readPosition = 0;
 }
开发者ID:CodeDevLab,项目名称:TS3AudioBot,代码行数:8,代码来源:PositionedStreamReader.cs

示例11: AsyncTextReader

 public AsyncTextReader(IAsyncDataSource dataSource, Encoding encoding, int bufferSize = DefaultBufferSize)
     : base()
 {
     _DataSource = dataSource;
     _Encoding = encoding;
     _Decoder = _Encoding.GetDecoder();
     _BufferSize = Math.Max(MinimumBufferSize, bufferSize);
     AllocateBuffer();
 }
开发者ID:pakoito,项目名称:Fracture,代码行数:9,代码来源:IO.cs

示例12: AsyncLineReader

 public AsyncLineReader(Stream stream, Encoding encoding, int bufferSize, int maxLineLength)
 {
     this.stream = stream;
     this.decoder = encoding.GetDecoder();
     this.readBuffer = new byte[bufferSize];
     this.decodeBuffer = new char[bufferSize];
     this.maxLineLength = maxLineLength;
     StartRead();
 }
开发者ID:runt18,项目名称:vss2git-1,代码行数:9,代码来源:AsyncLineReader.cs

示例13: CancellableStreamReader

 public CancellableStreamReader(Stream stream, Encoding encoding)
 {
     _stream = stream;
     _decoder = encoding.GetDecoder();
     _byteBuffer = new byte[BufferLength];
     _buffer = new char[encoding.GetMaxCharCount(BufferLength)];
     _bufferedLength = -1;
     _bufferCursor = -1;
 }
开发者ID:karno,项目名称:StarryEyes,代码行数:9,代码来源:CancellableStreamReader.cs

示例14: ConvertEncoding

 public static string ConvertEncoding(string value, Encoding src, Encoding trg)
 {
     Decoder dec = src.GetDecoder();
     byte[] ba = trg.GetBytes(value);
     int len = dec.GetCharCount(ba, 0, ba.Length);
     char[] ca = new char[len];
     dec.GetChars(ba, 0, ba.Length, ca, 0);
     return new string(ca);
 }
开发者ID:dmziryanov,项目名称:ApecAuto,代码行数:9,代码来源:RegisterOnlineFranch.aspx.cs

示例15: TextSource

 TextSource(Encoding encoding)
 {
     _buffer = new Byte[BufferSize];
     _chars = new Char[BufferSize + 1];
     _raw = new MemoryStream();
     _index = 0;
     _encoding = encoding ?? TextEncoding.Utf8;
     _decoder = _encoding.GetDecoder();
 }
开发者ID:tsu1980,项目名称:AngleSharp,代码行数:9,代码来源:TextSource.cs


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