本文整理汇总了C#中System.Text.Decoder类的典型用法代码示例。如果您正苦于以下问题:C# Decoder类的具体用法?C# Decoder怎么用?C# Decoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Decoder类属于System.Text命名空间,在下文中一共展示了Decoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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");
}
示例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);
}
示例3: 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();
}
示例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");
}
示例5: 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];
}
示例6: Main
static void Main(string[] args)
{
//第一个参数是第三方平台
//第二个参数是平台账号信息,若此处不设置Account,则需要在策略代码中设置默认值
var decoder = new Decoder(Platform.RuoKuai, new Account
{
SoftId = 0, // 软件ID(此ID需要注册开发者账号才可获得)
TypeId = 0, // 验证码类型(四位字符或其他类型的验证码,根据各平台设置不同值)
SoftKey = null, //软件Key (此Key也需要注册开发者账号才可获得)
UserName = null, //账号(此账号为打码平台的普通用户账号,开发者账号不能进行图片识别)
Password = null //密码
});
decoder.OnStart += (s, e) =>
{
Console.WriteLine("验证码("+e.FilePath+")识别启动……");
};
decoder.OnCompleted += (s, e) =>
{
Console.WriteLine("验证码(" + e.FilePath + ")识别完成:" + e.Code + ",耗时:" + (e.Milliseconds/1000) + "秒,线程ID:"+e.ThreadId);
};
decoder.OnError += (s, e) =>
{
Console.WriteLine("验证码识别出错:" + e.Exception.Message);
};
for (var i = 1; i <= 3; i++)
{
decoder.Decode("c:\\checkcode"+i+".png");
}
Console.ReadKey();
}
示例7: 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;
}
}
示例8: ContentReader
public ContentReader(Stream stream, long length, Encoding encoding = null) {
_stream = stream;
_length = length;
if (encoding != null) {
_decoder = encoding.GetDecoder();
}
}
示例9: StaticUtils
static StaticUtils()
{
asciiDecoder = Encoding.ASCII.GetDecoder();
utf8Encoder = Encoding.UTF8.GetEncoder();
utf8Decoder = Encoding.UTF8.GetDecoder();
}
示例10: 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;
}
}
示例11: XmlParser
/// <summary>
/// コンストラクタです。
/// </summary>
public XmlParser(Stream stream)
{
this.stream = stream;
this.element = this.name = this.data = "";
this.attr = new Hashtable();
this.dec = Encoding.Default.GetDecoder();
this.letter = false;
}
示例12: UTF8SanitizerStream
public UTF8SanitizerStream(string pattern, string substitute, Stream output)
{
_pattern = pattern;
_substitute = substitute;
_output = output;
_decoder = Encoding.UTF8.GetDecoder();
_buffer = String.Empty;
}
示例13: PositionedStreamReader
public PositionedStreamReader(Stream stream, Encoding encoding)
{
this.stream = stream;
this.encoding = encoding;
decoder = encoding.GetDecoder();
bufferpos = 0;
readPosition = 0;
}
示例14: ReadATTRIBUTEWORD
/// <summary>
/// Reads an ATTRIBUTEWORD from the byte buffer.
/// </summary>
/// <param name="buffer">buffer containing serialized data</param>
/// <param name="offset">reference to an offset variable; upon entry offset
/// reflects the position within the buffer where reading should begin.
/// Upon success the offset will be incremented by the number of bytes that are used.</param>
/// <param name="coder">Decoder used to translate byte data to character data</param>
/// <returns>an ATTRIBUTEWORD value taken from the buffer</returns>
public static string ReadATTRIBUTEWORD(byte[] buffer, ref int offset, Decoder coder)
{
#if DEBUG
if (buffer == null) throw new ArgumentNullException("buffer");
if (offset < 0 || offset > buffer.Length - 1) throw new BadLwesDataException(String.Concat("Expected ATTRIBUTEWORD at offset ", offset));
#endif
return ReadStringWithByteLengthPrefix(buffer, ref offset, coder);
}
示例15: RequestState
//bool disposed;
public RequestState()
{
BufferRead = new byte[BufferSize];
RequestData = new StringBuilder(String.Empty);
Request = null;
ResponseStream = null;
StreamDecode = Encoding.UTF8.GetDecoder();
}