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


C# Encoding.GetMaxByteCount方法代码示例

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


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

示例1: 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

示例2: UrlEncode

 public static string UrlEncode(string s, Encoding Enc)
 {
     if (s == null)
     {
         return null;
     }
     if (s == "")
     {
         return "";
     }
     bool flag = false;
     int length = s.Length;
     for (int i = 0; i < length; i++)
     {
         char c = s[i];
         if (((((c < '0') || ((c < 'A') && (c > '9'))) || ((c > 'Z') && (c < 'a'))) || (c > 'z')) && !NotEncoded(c))
         {
             flag = true;
             break;
         }
     }
     if (!flag)
     {
         return s;
     }
     byte[] bytes = new byte[Enc.GetMaxByteCount(s.Length)];
     int count = Enc.GetBytes(s, 0, s.Length, bytes, 0);
     return Encoding.ASCII.GetString(UrlEncodeToBytes(bytes, 0, count));
 }
开发者ID:fabriceleal,项目名称:YoutubeDesktop,代码行数:29,代码来源:HttpUtility.cs

示例3: 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

示例4: 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

示例5: UrlEncode

        public static string UrlEncode(string s, Encoding Enc)
        {
            if (s == null)
                return null;

            if (s == String.Empty)
                return String.Empty;

            bool needEncode = false;
            int len = s.Length;
            for (int i = 0; i < len; i++)
            {
                char c = s[i];
                if ((c < '0') || (c < 'A' && c > '9') || (c > 'Z' && c < 'a') || (c > 'z'))
                {
                    if (HttpEncoder.NotEncoded(c))
                        continue;

                    needEncode = true;
                    break;
                }
            }

            if (!needEncode)
                return s;

            // avoided GetByteCount call
            byte[] bytes = new byte[Enc.GetMaxByteCount(s.Length)];
            int realLen = Enc.GetBytes(s, 0, s.Length, bytes, 0);
            byte[] t2 = UrlEncodeToBytes(bytes, 0, realLen);
            return Encoding.UTF8.GetString(t2, 0, t2.Length);
        }
开发者ID:sopel,项目名称:Salient.JsonClient,代码行数:32,代码来源:HttpUtility.cs

示例6: HttpResponseStreamWriter

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

            if (!stream.CanWrite)
            {
                throw new ArgumentException(Resources.HttpResponseStreamWriter_StreamNotWritable, nameof(stream));
            }

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

            _stream = stream;
            Encoding = encoding;
            _charBufferSize = bufferSize;

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

            _encoder = encoding.GetEncoder();
            _byteBuffer = new byte[encoding.GetMaxByteCount(bufferSize)];
            _charBuffer = new char[bufferSize];
        }
开发者ID:phinq19,项目名称:git_example,代码行数:30,代码来源:HttpResponseStreamWriter.cs

示例7: RubyEncoding

 private RubyEncoding(Encoding/*!*/ encoding, Encoding/*!*/ strictEncoding, int ordinal) {
     Assert.NotNull(encoding, strictEncoding);
     _ordinal = ordinal;
     _encoding = encoding;
     _strictEncoding = strictEncoding;
     _maxBytesPerChar = strictEncoding.GetMaxByteCount(1);
     _isAsciiIdentity = AsciiIdentity(encoding);
 }
开发者ID:rpattabi,项目名称:ironruby,代码行数:8,代码来源:RubyEncoding.cs

示例8: InternalReaderBase

		protected InternalReaderBase(Encoding encoding, int bufferSize)
		{
			encoding_ = encoding;
			isSingleByte_ = encoding_.GetMaxByteCount(1) == 1;
			buffer_ = new byte[bufferSize];
			handle_ = GCHandle.Alloc(buffer_, GCHandleType.Pinned);
			basePointer_ = handle_.AddrOfPinnedObject();
		}
开发者ID:kekyo,项目名称:CenterCLR.ExaSerializers,代码行数:8,代码来源:InternalReaderBase_Unsafe.cs

示例9: TextReaderStream

 public TextReaderStream(TextReader textReader, Encoding encoding, int bufferSize = 4096)
 {
     _textReader = textReader;
     _encoding = encoding;
     _maxByteCountPerChar = _encoding.GetMaxByteCount(1);
     _encoder = encoding.GetEncoder();
     if (bufferSize <= 0) throw new ArgumentOutOfRangeException("bufferSize", "zero or negative");
     _charBuffer = new char[bufferSize];
 }
开发者ID:dmit25,项目名称:ntextcat,代码行数:9,代码来源:TextReaderStream.cs

示例10: HttpResponseStreamWriter

 public HttpResponseStreamWriter(Stream stream, Encoding encoding, int bufferSize)
 {
     _stream = stream;
     Encoding = encoding;
     _encoder = encoding.GetEncoder();
     _charBufferSize = bufferSize;
     _charBuffer = new ArraySegment<char>(new char[bufferSize]);
     _byteBuffer = new ArraySegment<byte>(new byte[encoding.GetMaxByteCount(bufferSize)]);
 }
开发者ID:benaadams,项目名称:mvc-sandbox,代码行数:9,代码来源:HttpResponseStreamWriter.cs

示例11: BinaryNBOReader

 /// <summary>
 /// Creates a new stream reader with a custom encoding.
 /// </summary>
 /// <param name="input">underlying input stream</param>
 /// <param name="encoding">custom encoding</param>
 public BinaryNBOReader(Stream input, Encoding encoding)
     : base(input, encoding)
 {
     int maxByteCount = encoding.GetMaxByteCount(1);
     if (maxByteCount < 0x10)
     {
         maxByteCount = 0x10;
     }
     buffer = new byte[maxByteCount];
 }
开发者ID:jmptrader,项目名称:Fudge-CSharp,代码行数:15,代码来源:BinaryNBOReader.cs

示例12: TestEncoding

 private void TestEncoding(Encoding enc, int byteCount, int maxByteCount, byte[] bytes)
 {
     Assert.Equal(byteCount, enc.GetByteCount(s_myChars));
     Assert.Equal(maxByteCount, enc.GetMaxByteCount(s_myChars.Length));
     Assert.Equal(enc.GetBytes(s_myChars), bytes);
     Assert.Equal(enc.GetCharCount(bytes), s_myChars.Length);
     Assert.Equal(enc.GetChars(bytes), s_myChars);
     Assert.Equal(enc.GetString(bytes, 0, bytes.Length), s_myString);
     Assert.NotEqual(0, enc.GetHashCode());
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:10,代码来源:ConvertUnicodeEncodings.cs

示例13: SetColumn

        /// <summary>
        /// Modifies a single column value in a modified record to be inserted or to
        /// update the current record.
        /// </summary>
        /// <param name="sesid">The session to use.</param>
        /// <param name="tableid">The cursor to update. An update should be prepared.</param>
        /// <param name="columnid">The columnid to set.</param>
        /// <param name="data">The data to set.</param>
        /// <param name="encoding">The encoding used to convert the string.</param>
        /// <param name="grbit">SetColumn options.</param>
        public static void SetColumn(
            JET_SESID sesid, JET_TABLEID tableid, JET_COLUMNID columnid, string data, Encoding encoding, SetColumnGrbit grbit)
        {
            CheckEncodingIsValid(encoding);

            if (null == data)
            {
                JetSetColumn(sesid, tableid, columnid, null, 0, grbit, null);
            }
            else if (0 == data.Length)
            {
                JetSetColumn(sesid, tableid, columnid, null, 0, grbit | SetColumnGrbit.ZeroLength, null);
            }
            else if (Encoding.Unicode == encoding)
            {
                // Optimization for setting Unicode strings.
                unsafe
                {
                    fixed (char* buffer = data)
                    {
                        JetSetColumn(
                            sesid,
                            tableid,
                            columnid,
                            new IntPtr(buffer),
                            checked(data.Length * sizeof(char)),
                            grbit,
                            null);
                    }
                }
            }
            else if (encoding.GetMaxByteCount(data.Length) <= Caches.ColumnCache.BufferSize)
            {
                // The encoding output will fix in a cached buffer. Get one to avoid 
                // more memory allocations.
                byte[] buffer = Caches.ColumnCache.Allocate();
                unsafe
                {
                    fixed (char* chars = data)
                    fixed (byte* bytes = buffer)
                    {
                        int dataSize = encoding.GetBytes(chars, data.Length, bytes, buffer.Length);
                        JetSetColumn(sesid, tableid, columnid, new IntPtr(bytes), dataSize, grbit, null);
                    }                    
                }

                Caches.ColumnCache.Free(ref buffer);
            }
            else
            {
                byte[] bytes = encoding.GetBytes(data);
                JetSetColumn(sesid, tableid, columnid, bytes, bytes.Length, grbit, null);
            }
        }
开发者ID:925coder,项目名称:ravendb,代码行数:64,代码来源:SetColumnHelpers.cs

示例14: Initialize

		internal void Initialize(Encoding encoding, int bufferSize) {
			internalEncoding = encoding;
			decode_pos = byte_pos = 0;
			int BufferSize = Math.Max(bufferSize, MinimumBufferSize);
			decode_buf = new char [BufferSize];
			byte_buf = new byte [encoding.GetMaxByteCount (BufferSize)];

			// Fixes bug http://bugzilla.ximian.com/show_bug.cgi?id=74513
			if (internalStream.CanSeek && internalStream.Position > 0)
				preamble_done = true;
		}
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:11,代码来源:StreamWriter.cs

示例15: MyBinaryReader

 public MyBinaryReader(Stream stream, Encoding encoding)
     : base(stream, encoding)
 {
     this.m_decoder = encoding.GetDecoder();
     this.m_maxCharsSize = encoding.GetMaxCharCount(0x80);
     int maxByteCount = encoding.GetMaxByteCount(1);
     if (maxByteCount < 0x10)
     {
         maxByteCount = 0x10;
     }
 }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:11,代码来源:MyBinaryReader.cs


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