本文整理汇总了C#中System.Text.Encoding.GetEncoder方法的典型用法代码示例。如果您正苦于以下问题:C# Encoding.GetEncoder方法的具体用法?C# Encoding.GetEncoder怎么用?C# Encoding.GetEncoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.Encoding
的用法示例。
在下文中一共展示了Encoding.GetEncoder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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];
}
示例2: BinaryWriter
// Protected default constructor that sets the output stream
// to a null stream (a bit bucket).
protected BinaryWriter()
{
OutStream = Stream.Null;
_buffer = new byte[16];
_encoding = EncodingCache.UTF8NoBOM;
_encoder = _encoding.GetEncoder();
}
示例3: BinaryWriter
// Protected default constructor that sets the output stream
// to a null stream (a bit bucket).
protected BinaryWriter()
{
OutStream = Stream.Null;
_buffer = new byte[16];
_encoding = new UTF8Encoding(false, true);
_encoder = _encoding.GetEncoder();
}
示例4: EndianWriter
// Protected default constructor that sets the output stream
// to a null stream (a bit bucket).
protected EndianWriter()
{
OutStream = Stream.Null;
buffer = new byte[16];
Encoding = new UTF8Encoding(false, true);
encoder = Encoding.GetEncoder();
}
示例5: 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)]);
}
示例6: 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];
}
示例7: TranscodingStream
private TranscodingStream(Stream stream, Encoding outEncoding)
{
if (stream == null)
throw new ArgumentNullException("stream");
if (outEncoding == null)
throw new ArgumentNullException("outEncoding");
this._stream = stream;
this._encoder = outEncoding.GetEncoder();
}
示例8: StringToPtr
public static IntPtr StringToPtr(string value, Encoding encoding)
{
var encoder = encoding.GetEncoder();
var length = encoding.GetByteCount(value);
// The encoded value is null terminated that's the reason for the '+1'.
var encodedValue = new byte[length + 1];
encoding.GetBytes(value, 0, value.Length, encodedValue, 0);
var handle = Marshal.AllocHGlobal(new IntPtr(encodedValue.Length));
Marshal.Copy(encodedValue, 0, handle, encodedValue.Length);
return handle;
}
示例9: SHA1TextReader
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <param name="encoding"></param>
public SHA1TextReader(TextReader input, Encoding encoding)
: base()
{
this.input = input;
this.encoder = encoding.GetEncoder();
this.sha1 = SHA1.Create();
this.ibuf = new char[bufferSize];
this.obuf = new byte[bufferSize];
this.ibufIndex = 0;
}
示例10: convert
public static String convert(string sourceValue, Encoding source, Encoding target)
{
Encoder encoder = source.GetEncoder();
Decoder decoder = target.GetDecoder();
byte[] cpBytes = source.GetBytes(sourceValue);
int bytesCount = source.GetByteCount(sourceValue);
byte[] utfBytes = Encoding.Convert(source, target, cpBytes);
char[] utfChars = new char[bytesCount];
decoder.GetChars(utfBytes, 0, utfBytes.Length, utfChars, 0);
return new String(utfChars);
}
示例11: AsyncStreamWriter
public AsyncStreamWriter(Stream stream, Encoding encoding, int initialBufferCapacity = DefaultIniBufferCapacity, int maxBufferCapacity = DefaultMaxBufferCapacity)
{
if (initialBufferCapacity < 4)
throw new ArgumentOutOfRangeException("initialBufferCapacity");
if (initialBufferCapacity > maxBufferCapacity)
maxBufferCapacity = initialBufferCapacity;
_stream = stream;
_buffer = new byte[initialBufferCapacity];
_maxBufferCapacity = maxBufferCapacity;
_encoder = encoding.GetEncoder();
}
示例12: BufferedBinaryWriter
public unsafe BufferedBinaryWriter(Stream output, Encoding encoding)
: base(output, encoding)
{
this.memoryPage = Pool.GetPage();
this.basePtr = this.memoryPage.BasePtr;
this.endPtr = this.memoryPage.EndPtr;
this.ptr = this.basePtr;
this.encoding = encoding;
this.encoder = encoding.GetEncoder();
this.charMaxByteCount = encoding.IsSingleByte ? 1 : encoding.GetMaxByteCount(1);
}
示例13: BinaryWriter
public BinaryWriter(Stream output, Encoding encoding)
{
if (output==null)
throw new ArgumentNullException("output");
if (encoding==null)
throw new ArgumentNullException("encoding");
if (!output.CanWrite)
throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotWritable"));
OutStream = output;
_buffer = new byte[16];
_encoding = encoding;
_encoder = _encoding.GetEncoder();
}
示例14: NpgsqlBuffer
internal NpgsqlBuffer(Stream underlying, int size, Encoding textEncoding)
{
if (size < MinimumBufferSize) {
throw new ArgumentOutOfRangeException("size", size, "Buffer size must be at least " + MinimumBufferSize);
}
Contract.EndContractBlock();
Underlying = underlying;
Size = size;
_buf = new byte[Size];
TextEncoding = textEncoding;
_textDecoder = TextEncoding.GetDecoder();
_textEncoder = TextEncoding.GetEncoder();
_tempCharBuf = new char[1024];
_workspace = new byte[8];
}
示例15: BinaryWriter
public BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
{
if (output==null)
throw new ArgumentNullException(nameof(output));
if (encoding==null)
throw new ArgumentNullException(nameof(encoding));
if (!output.CanWrite)
throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotWritable"));
Contract.EndContractBlock();
OutStream = output;
_buffer = new byte[16];
_encoding = encoding;
_encoder = _encoding.GetEncoder();
_leaveOpen = leaveOpen;
}