/// <summary> /// Writes contents of toPrint with default encoding /// </summary> /// <param name="toPrint">Content to write</param> public void Print(string toPrint) { if (string.IsNullOrEmpty(toPrint)) { throw new ArgumentException("toPrint cannot be empty or null", "toPrint"); } Print(CurrentEncoding.GetBytes(toPrint)); }
public void Read(TextReader stream) { if (stream == null) { // Error Message? Log? return; } string str = stream.ReadToEnd(); byte[] byteArray = CurrentEncoding.GetBytes(str); MemoryStream mstream = new MemoryStream(byteArray); mstream.Position = 0; //set just to make sure... this.Read(new BinaryReader(mstream, this.CurrentEncoding)); }
private void DetermineUnitSizeAndEndianess() { Span <byte> span = stackalloc byte[4]; if (CurrentEncoding is null) { // unknown encoding, assume UTF-8 UnitSize = 1; _isBigEndian = false; return; } switch (CurrentEncoding) { default: throw new Exception($"Unsupported encoding type {CurrentEncoding.GetType()}"); case UTF7Encoding utf7Encoding: case UTF8Encoding utf8Encoding: case ASCIIEncoding aSCIIEncoding: _isBigEndian = false; UnitSize = 1; break; case UTF32Encoding utf32Encoding: CurrentEncoding.GetBytes("a", span); _isBigEndian = span[0] == 0; UnitSize = 4; break; case UnicodeEncoding unicodeEncoding: CurrentEncoding.GetBytes("a", span); _isBigEndian = span[0] == 0; UnitSize = 2; break; } }
public override string ReadLine() { LineNumber++; string line = base.ReadLine(); if (line != null) { if (ToServerEncoding) { return(Extensions.ConvertEncoding(line, CurrentEncoding, SdeAppConfiguration.EncodingServer, _isUtf8)); } if (ToClientEncoding) { return(Extensions.ConvertEncoding(line, CurrentEncoding, EncodingService.DisplayEncoding, _isUtf8)); } if (_auto) { return(EncodingService.DisplayEncoding.GetString(CurrentEncoding.GetBytes(line))); } } return(line); }
public override void Write(byte[] buffer, int offset, int count) { string strBuffer = CurrentEncoding.GetString(buffer, offset, count); #region =如果不是HTML文档,不作处理= var bof = new Regex("<html", RegexOptions.IgnoreCase); if (!bof.IsMatch(strBuffer.ToString())) { responseStream.Write(buffer, offset, count); return; } #endregion //Regex eof = new Regex("</html>", RegexOptions.IgnoreCase); //if (!eof.IsMatch(strBuffer)) //{ // responseHtml.Append(strBuffer); //} //else //{ //} responseHtml.Append(strBuffer); string finalHtml = responseHtml.ToString(); finalHtml = _func(finalHtml); // Transform the response and write it back out byte[] data = CurrentEncoding.GetBytes(finalHtml); responseStream.Write(data, 0, data.Length); }
public void Print(string toPrint) { Print(CurrentEncoding.GetBytes(toPrint)); }
public void Print(string toPrint, IContentParameters parameters) { IContentReplacer replacer = new ContentReplacer(parameters); Print(replacer.Replace(CurrentEncoding.GetBytes(toPrint))); }
/// <summary> /// Gets the position of the internal <see cref="Stream"/>. /// </summary> /// <returns>The position in the stream.</returns> public virtual long Position() { return(BaseStream.Position + (_charPos > 0 ? CurrentEncoding.GetBytes(_charBuffer, 0, _charPos + 1).Length : 0)); }