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


C# Text.Encoding类代码示例

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


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

示例1: SocketServer

        public SocketServer(int port, ErrorLogger errorLog, FileLogger debugLog)
            : base(errorLog, debugLog)
        {
            try
            {
                this.encoding = Encoding.ASCII;
                this.port = port;
                this.clients = new List<SocketClient>();

                this.listenerLoopThread = new Thread(this.ListenerLoop);
                this.listenerLoopThread.IsBackground = true;
                this.listenerLoopThread.Start();

                this.clientsLoopThread = new Thread(this.ClientsLoop);
                this.clientsLoopThread.IsBackground = true;
                this.clientsLoopThread.Start();

                this.Store("Host.Version", AssemblyInfo.SarVersion);
                this.Store("Host.Port", this.port.ToString());
                this.Store("Host.Clients", this.clients.Count.ToString());
                this.Store("Host.Application.Product", AssemblyInfo.Product);
                this.Store("Host.Application.Version", AssemblyInfo.Version);
            }
            catch (Exception ex)
            {
                this.Log(ex);
            }
        }
开发者ID:cwillison94,项目名称:sar-tool,代码行数:28,代码来源:SocketServer.cs

示例2: FileReverseReader

 public FileReverseReader(string path)
 {
     disposed = false;
     file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     encoding = FindEncoding(file);
     SetupCharacterStartDetector();
 }
开发者ID:andy250,项目名称:caselog,代码行数:7,代码来源:FileReverseReader.cs

示例3: Arrange

        protected void Arrange()
        {
            var random = new Random();
            _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture);
            _operationTimeout = TimeSpan.FromSeconds(30);
            _encoding = Encoding.UTF8;
            _disconnectedRegister = new List<EventArgs>();
            _errorOccurredRegister = new List<ExceptionEventArgs>();
            _channelDataEventArgs = new ChannelDataEventArgs(
                (uint)random.Next(0, int.MaxValue),
                new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) });

            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
            _channelMock = new Mock<IChannelSession>(MockBehavior.Strict);

            _sequence = new MockSequence();
            _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object);
            _channelMock.InSequence(_sequence).Setup(p => p.Open());
            _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true);

            _subsystemSession = new SubsystemSessionStub(
                _sessionMock.Object,
                _subsystemName,
                _operationTimeout,
                _encoding);
            _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args);
            _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args);
            _subsystemSession.Connect();
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:29,代码来源:SubsystemSession_OnChannelDataReceived_Connected.cs

示例4: EdifactWriter

 public EdifactWriter(Stream stream, Encoding encoding, EdifactCharacterSet edifactCharacterSet, char replacementCharacter, bool normalize = true)
     : base(stream, encoding)
 {
     this._fallbackChar = replacementCharacter;
     this._edifactCharacterSet = edifactCharacterSet;
     this._normalize = normalize;
 }
开发者ID:gvdwiele,项目名称:CharacterTranscoder,代码行数:7,代码来源:EdifactWriter.cs

示例5: DownloadSecondaryServerVisitor

        /// <summary>
        /// Initializes a new instance of the <see cref="DownloadSecondaryServerVisitor"/> class.
        /// </summary>
        /// <param name="encoding">The encoding used to read and write strings.</param>
        public DownloadSecondaryServerVisitor(Encoding encoding)
        {
            // You should use an IoC container to do this.
            TcpReaderFactory = new TcpReaderFactory();

            CurrentEncoding = encoding;
        }
开发者ID:joe-williams-cccu,项目名称:OSIRTv2,代码行数:11,代码来源:DownloadSecondaryServerVisitor.cs

示例6: SftpOpenDirRequest

 public SftpOpenDirRequest(uint protocolVersion, uint requestId, string path, Encoding encoding, Action<SftpHandleResponse> handleAction, Action<SftpStatusResponse> statusAction)
     : base(protocolVersion, requestId, statusAction)
 {
     this.Path = path;
     this.Encoding = encoding;
     this.SetAction(handleAction);
 }
开发者ID:npcook,项目名称:terminal,代码行数:7,代码来源:SftpOpenDirRequest.cs

示例7: Get

 /// <summary>
 ///     获取远程信息
 /// </summary>
 /// <param name="url">请求地址</param>
 /// <param name="encoding">请求编码</param>
 /// <param name="wc">客户端</param>
 public static string Get(string url, Encoding encoding = null, WebClient wc = null)
 {
     if (string.IsNullOrWhiteSpace(url)) { return string.Empty; }
     url = url.Replace("\\", "/");
     if (encoding == null) encoding = Encoding.UTF8;
     var isNew = wc == null;
     if (wc == null)
     {
         wc = new WebClient();
         wc.Proxy = null;
         wc.Headers.Add("Accept", "*/*");
         wc.Headers.Add("Referer", url);
         wc.Headers.Add("Cookie", "bid=\"YObnALe98pw\";");
         wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.5 Safari/537.31");
     }
     string strResult = null;
     try
     {
         var data = wc.DownloadData(url);
         strResult = encoding.GetString(data);
     }
     catch { return string.Empty; }
     finally
     {
         if (!isNew) Cookies(wc);
         if (isNew) wc.Dispose();
     }
     return strResult;
 }
开发者ID:lirongjun0926,项目名称:Farseer.Net,代码行数:35,代码来源:Net.cs

示例8: RunTests

 private static void RunTests(Encoding enc, params string[] pathElements)
 {
     var engine = new FileHelperEngine<CustomersVerticalBar>();
     engine.Encoding = enc;
     Assert.AreEqual(enc, engine.Encoding);
     CoreRunTest(engine, pathElements);
 }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:7,代码来源:Encoding.cs

示例9: RunAsyncConstructor

        private static void RunAsyncConstructor(Encoding enc, params string[] pathElements)
        {
            var asyncEngine = new FileHelperAsyncEngine<CustomersVerticalBar>(enc);
            Assert.AreEqual(enc, asyncEngine.Encoding);

            CoreRunAsync(asyncEngine, pathElements);
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:7,代码来源:Encoding.cs

示例10: CreateText

        public SourceText CreateText(Stream stream, Encoding defaultEncoding, CancellationToken cancellationToken = default(CancellationToken))
        {
            // this API is for a case where user wants us to figure out encoding from the given stream.
            // if defaultEncoding is given, we will use it if we couldn't figure out encoding used in the stream ourselves.
            Debug.Assert(stream != null);
            Debug.Assert(stream.CanSeek);
            Debug.Assert(stream.CanRead);

            if (defaultEncoding == null)
            {
                // Try UTF-8
                try
                {
                    return CreateTextInternal(stream, s_throwingUtf8Encoding, cancellationToken);
                }
                catch (DecoderFallbackException)
                {
                    // Try Encoding.Default
                    defaultEncoding = Encoding.Default;
                }
            }

            try
            {
                return CreateTextInternal(stream, defaultEncoding, cancellationToken);
            }
            catch (DecoderFallbackException)
            {
                return null;
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:31,代码来源:EditorTextFactoryService.cs

示例11: CommonVolumeDescriptor

        public CommonVolumeDescriptor(byte[] src, int offset, Encoding enc)
            : base(src, offset)
        {
            CharacterEncoding = enc;

            SystemIdentifier = IsoUtilities.ReadChars(src, offset + 8, 32, CharacterEncoding);
            VolumeIdentifier = IsoUtilities.ReadChars(src, offset + 40, 32, CharacterEncoding);
            VolumeSpaceSize = IsoUtilities.ToUInt32FromBoth(src, offset + 80);
            VolumeSetSize = IsoUtilities.ToUInt16FromBoth(src, offset + 120);
            VolumeSequenceNumber = IsoUtilities.ToUInt16FromBoth(src, offset + 124);
            LogicalBlockSize = IsoUtilities.ToUInt16FromBoth(src, offset + 128);
            PathTableSize = IsoUtilities.ToUInt32FromBoth(src, offset + 132);
            TypeLPathTableLocation = Utilities.ToUInt32LittleEndian(src, offset + 140);
            OptionalTypeLPathTableLocation = Utilities.ToUInt32LittleEndian(src, offset + 144);
            TypeMPathTableLocation = Utilities.BitSwap(Utilities.ToUInt32LittleEndian(src, offset + 148));
            OptionalTypeMPathTableLocation = Utilities.BitSwap(Utilities.ToUInt32LittleEndian(src, offset + 152));
            DirectoryRecord.ReadFrom(src, offset + 156, CharacterEncoding, out RootDirectory);
            VolumeSetIdentifier = IsoUtilities.ReadChars(src, offset + 190, 318 - 190, CharacterEncoding);
            PublisherIdentifier = IsoUtilities.ReadChars(src, offset + 318, 446 - 318, CharacterEncoding);
            DataPreparerIdentifier = IsoUtilities.ReadChars(src, offset + 446, 574 - 446, CharacterEncoding);
            ApplicationIdentifier = IsoUtilities.ReadChars(src, offset + 574, 702 - 574, CharacterEncoding);
            CopyrightFileIdentifier = IsoUtilities.ReadChars(src, offset + 702, 739 - 702, CharacterEncoding);
            AbstractFileIdentifier = IsoUtilities.ReadChars(src, offset + 739, 776 - 739, CharacterEncoding);
            BibliographicFileIdentifier = IsoUtilities.ReadChars(src, offset + 776, 813 - 776, CharacterEncoding);
            CreationDateAndTime = IsoUtilities.ToDateTimeFromVolumeDescriptorTime(src, offset + 813);
            ModificationDateAndTime = IsoUtilities.ToDateTimeFromVolumeDescriptorTime(src, offset + 830);
            ExpirationDateAndTime = IsoUtilities.ToDateTimeFromVolumeDescriptorTime(src, offset + 847);
            EffectiveDateAndTime = IsoUtilities.ToDateTimeFromVolumeDescriptorTime(src, offset + 864);
            FileStructureVersion = src[offset + 881];
        }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:30,代码来源:CommonVolumeDescriptor.cs

示例12: TextFileMarger

 /// <summary>
 /// 新しいこのクラスのインスタンスを構築します。
 /// </summary>
 /// <param name="sourcePath">比較元ファイルパス</param>
 /// <param name="destinationPath">比較先ファイルパス</param>
 /// <param name="encode">ファイルのエンコード</param>
 public TextFileMarger(string sourcePath, string destinationPath, Encoding encode)
      : base()
 {
     SourcePath = sourcePath;
     DestinationPath = destinationPath;
     Encoding = encode;
 }
开发者ID:Ricordanza,项目名称:Ricordanza.kernel,代码行数:13,代码来源:TextFileMerger.cs

示例13: TestSingleEncoding

 private static void TestSingleEncoding(string text, int bufferSize, Encoding encoding)
 {
     DisposeCheckingMemoryStream stream = new DisposeCheckingMemoryStream(encoding.GetBytes(text));
     var reader = new ReverseLineReader(() => stream, encoding, bufferSize);
     AssertLines(new LineReader(() => new StringReader(text)).Reverse(), reader);
     Assert.IsTrue(stream.Disposed);
 }
开发者ID:dioptre,项目名称:nkd,代码行数:7,代码来源:ReverseLineReaderTest.cs

示例14: XmlParserContext

 /// <include file='doc\XmlParserContext.uex' path='docs/doc[@for="XmlParserContext.XmlParserContext3"]/*' />
 public XmlParserContext(XmlNameTable nt, XmlNamespaceManager nsMgr, String docTypeName,
                   String pubId, String sysId, String internalSubset, String baseURI,
                   String xmlLang, XmlSpace xmlSpace, Encoding enc)
 {
     
     if (nsMgr != null) {
         if (nt == null) {
             _nt = nsMgr.NameTable;
         }
         else {
             if ( (object)nt != (object)  nsMgr.NameTable ) {
                 throw new XmlException(Res.Xml_NotSameNametable);
             }
             _nt = nt;
         }
     }
     else {
         _nt = nt;
     }
     
     _nsMgr              = nsMgr;
     _docTypeName        = (null == docTypeName ? String.Empty : docTypeName);
     _pubId              = (null == pubId ? String.Empty : pubId);
     _sysId              = (null == sysId ? String.Empty : sysId);
     _internalSubset     = (null == internalSubset ? String.Empty : internalSubset);
     _baseURI            = (null == baseURI ? String.Empty : baseURI);
     _xmlLang            = (null == xmlLang ? String.Empty : xmlLang);
     _xmlSpace           = xmlSpace;
     _encoding           = enc;
     
 }
开发者ID:ArildF,项目名称:masters,代码行数:32,代码来源:xmlparsercontext.cs

示例15: StructureSegment

 public StructureSegment(byte[] pBuffer, int pStart, int pLength, byte locale)
 {
     mBuffer = new byte[pLength];
     try
     {
         switch (locale)
         {
             case MapleLocale.KOREA:
             case MapleLocale.KOREA_TEST:
                 encoding = Encoding.GetEncoding(51949); // EUC_KR
                 break;
             case MapleLocale.JAPAN:
                 encoding = Encoding.GetEncoding(50222); // Shift_JIS
                 break;
             case MapleLocale.CHINA:
                 encoding = Encoding.GetEncoding(54936); // GB18030
                 break;
             case MapleLocale.TESPIA:
                 encoding = Encoding.Default;
                 break;
             case MapleLocale.TAIWAN:
                 encoding = Encoding.GetEncoding("BIG5-HKSCS");
                 break;
             default:
                 encoding = Encoding.UTF8;
                 break;
         }
     }
     catch
     {
         encoding = Encoding.UTF8;
     }
     Buffer.BlockCopy(pBuffer, pStart, mBuffer, 0, pLength);
 }
开发者ID:diamondo25,项目名称:MultiShark,代码行数:34,代码来源:StructureSegment.cs


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