本文整理汇总了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");
}
示例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: 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;
}
}
示例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;
}
示例5: ContentReader
public ContentReader(Stream stream, long length, Encoding encoding = null) {
_stream = stream;
_length = length;
if (encoding != null) {
_decoder = encoding.GetDecoder();
}
}
示例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();
}
示例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];
}
示例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;
}
}
示例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");
}
示例10: PositionedStreamReader
public PositionedStreamReader(Stream stream, Encoding encoding)
{
this.stream = stream;
this.encoding = encoding;
decoder = encoding.GetDecoder();
bufferpos = 0;
readPosition = 0;
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}