本文整理汇总了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);
}
}
示例2: FileReverseReader
public FileReverseReader(string path)
{
disposed = false;
file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
encoding = FindEncoding(file);
SetupCharacterStartDetector();
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例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];
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}