/// <summary>
 ///
 /// </summary>
 /// <param name="fileName">文件名,包括文件路径</param>
 public CsvStreamReader(string fileName)
 {
     this.rowAL = new ArrayList();
     this.fileName = fileName;
     this.encoding = Encoding.Default;
     LoadCsvFile();
 }
Esempio n. 2
0
 ///<summary>
 ///采用https协议GET方式访问网络,根据传入的URl地址,得到响应的数据字符串。
 ///</summary>
 ///<param name="URL">url地址</param>
 ///<param name="objencoding">编码方式例如:System.Text.Encoding.UTF8;</param>
 ///<returns>String类型的数据</returns>
 public string GetHttpRequestStringByNUll_Get(string URL, Encoding objencoding)
 {
     //准备参数
     SetRequest(URL, "GET", "text/html, application/xhtml+xml, */*", "text/html", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", objencoding);
     //调用专门读取数据的类
     return GetHttpRequestData("");
 }
	public override bool Decode(Encoding encoding)
	{
//		List<object> encoded = new List<object>(encodings);
		
		if (!encoding.Validate(	EncodingType.Group,
								EncodingType.Group
								))
		{
			Debug.Log ("Could not decode generator \n"+encoding.DebugString());
			return false;
		}
		Debug.Log ("Decoding Generator: "+encoding.DebugString());
		base.Decode(encoding.SubEncoding(0));
		
		if (toGenerateConstruction != null)
		{
			ObjectPoolManager.DestroyObject(toGenerateConstruction);
			toGenerateConstruction = null;
		}
		if (encoding.Count > 1)
		{
			toGenerateConstruction = Construction.DecodeCreate(encoding.SubEncoding(1));
			toGenerateConstruction.ignoreCollisions = true;
		}
		
		return true;
	}
 public static string Stringify(this Stream theStream, Encoding encoding = null)
 {
     using (var reader = new StreamReader(theStream, encoding ?? DefaultEncoding))
     {
         return reader.ReadToEnd();
     }
 }
 /// <summary>
 ///     A Stream extension method that reads a stream to the end.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="encoding">The encoding.</param>
 /// <returns>
 ///     The rest of the stream as a string, from the current position to the end. If the current position is at the
 ///     end of the stream, returns an empty string ("").
 /// </returns>
 public static string ReadToEnd(this Stream @this, Encoding encoding)
 {
     using (var sr = new StreamReader(@this, encoding))
     {
         return sr.ReadToEnd();
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="fileName">文件名,包括文件路径</param>
 /// <param name="encoding">文件编码</param>
 public CsvStreamReader(string fileName, Encoding encoding)
 {
     this.rowAL = new ArrayList();
     this.fileName = fileName;
     this.encoding = encoding;
     LoadCsvFile();
 }
Esempio n. 7
0
 /// <summary>
 /// 采用https协议GET|POST方式访问网络,根据传入的URl地址,得到响应的数据字符串。
 /// </summary>
 /// <param name="_URL"></param>
 /// <param name="_Method">请求方式Get或者Post</param>
 /// <param name="_Accept">Accept</param>
 /// <param name="_ContentType">ContentType返回类型</param>
 /// <param name="_UserAgent">UserAgent客户端的访问类型,包括浏览器版本和操作系统信息</param>
 /// <param name="_Encoding">读取数据时的编码方式</param>
 /// <param name="_Postdata">只有_Method为Post方式时才需要传入值</param>
 /// <returns>返回Html源代码</returns>
 public string GetHttpRequestString(string _URL, string _Method, string _Accept, string _ContentType, string _UserAgent, Encoding _Encoding, string _Postdata)
 {
     //准备参数
     SetRequest(_URL, _Method, _Accept, _ContentType, _UserAgent, _Encoding);
     //调用专门读取数据的类
     return GetHttpRequestData(_Postdata);
 }
Esempio n. 8
0
 private Stream CreateStream(string name, string fileNameExtension, Encoding encoding,
                           string mimeType, bool willSeek)
 {
     Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);
     m_streams.Add(stream);
     return stream;
 }
Esempio n. 9
0
        public static void VerifyEncoding(Encoding encoding, int codePage, EncoderFallback encoderFallback, DecoderFallback decoderFallback)
        {
            if (encoderFallback == null)
            {
                Assert.NotNull(encoding.EncoderFallback);
                Assert.Equal(codePage, encoding.EncoderFallback.GetHashCode());
            }
            else
            {
                Assert.Same(encoderFallback, encoding.EncoderFallback);
            }

            if (decoderFallback == null)
            {
                Assert.NotNull(encoding.DecoderFallback);
                Assert.Equal(codePage, encoding.DecoderFallback.GetHashCode());
            }
            else
            {
                Assert.Same(decoderFallback, encoding.DecoderFallback);
            }

            Assert.Empty(encoding.GetPreamble());
            Assert.False(encoding.IsSingleByte);
        }
Esempio n. 10
0
	public virtual bool Decode (Encoding encoding)
	{
		IntVector2 newLocation = new IntVector2(encoding.Int(0)-31, encoding.Int (1)-31);
		Mechanism placedMechanism = GridManager.instance.GetHexCell(newLocation).placedMechanism;
		
		bool didReplacedPart = false;
		if (placedMechanism != null) // we are replacing a part
		{
			if (placedMechanism.MechanismType == MechanismType && // we are replacing the same type of part
				placedMechanism.Location.IsEqualTo(newLocation) && // the location of the old part is the same as this new one (important for multicell mechanisms e.g. weldingRig)
				!placedMechanism.isSolutionMechanism) // is a level mechanism (not part of the solution, part of the problem ;p)
			{
				ObjectPoolManager.DestroyObject(placedMechanism);
				PlaceAtLocation(newLocation);
				isSolutionMechanism = false; // we use the already on board's movable (i.e. immovable)
				
			}
			else
			{
				// something went wrong, we are loading a mechanism on top of one that is different, or a solution mechanism
				Debug.LogError("Something went wrong, we are loading a mechanism on top of one that is different, or a solution mechanism");
				return false;
			}
		}
		else // this is a new part
		{
			PlaceAtLocation(newLocation);
			isSolutionMechanism = (int)encoding.Int(2) == 1;
		}
		
		return true;
	}
Esempio n. 11
0
        public static unsafe void GetByteCount_Invalid(Encoding encoding)
        {
            // Chars is null
            Assert.Throws<ArgumentNullException>(encoding is ASCIIEncoding ? "chars" : "s", () => encoding.GetByteCount((string)null));
            Assert.Throws<ArgumentNullException>("chars", () => encoding.GetByteCount((char[])null));
            Assert.Throws<ArgumentNullException>("chars", () => encoding.GetByteCount(null, 0, 0));

            // Index or count < 0
            Assert.Throws<ArgumentOutOfRangeException>("index", () => encoding.GetByteCount(new char[3], -1, 0));
            Assert.Throws<ArgumentOutOfRangeException>("count", () => encoding.GetByteCount(new char[3], 0, -1));

            // Index + count > chars.Length
            Assert.Throws<ArgumentOutOfRangeException>("chars", () => encoding.GetByteCount(new char[3], 0, 4));
            Assert.Throws<ArgumentOutOfRangeException>("chars", () => encoding.GetByteCount(new char[3], 1, 3));
            Assert.Throws<ArgumentOutOfRangeException>("chars", () => encoding.GetByteCount(new char[3], 2, 2));
            Assert.Throws<ArgumentOutOfRangeException>("chars", () => encoding.GetByteCount(new char[3], 3, 1));
            Assert.Throws<ArgumentOutOfRangeException>("chars", () => encoding.GetByteCount(new char[3], 4, 0));

            char[] chars = new char[3];
            fixed (char* pChars = chars)
            {
                char* pCharsLocal = pChars;
                Assert.Throws<ArgumentNullException>("chars", () => encoding.GetByteCount(null, 0));
                Assert.Throws<ArgumentOutOfRangeException>("count", () => encoding.GetByteCount(pCharsLocal, -1));
            }
        }
Esempio n. 12
0
    public ExchangeHTTP(HttpResponse response, string flag)
    {
        this.encoding = response.Output.Encoding;
        this.responseStream = response.Filter;

        this.flag = flag;
    }
Esempio n. 13
0
        public static void GetBytes(Encoding encoding, string source, int index, int count, byte[] bytes, int byteIndex, byte[] expectedBytes)
        {
            byte[] originalBytes = (byte[])bytes.Clone();

            if (index == 0 && count == source.Length)
            {
                // Use GetBytes(string)
                byte[] stringResultBasic = encoding.GetBytes(source);
                VerifyGetBytes(stringResultBasic, 0, stringResultBasic.Length, originalBytes, expectedBytes);

                // Use GetBytes(char[])
                byte[] charArrayResultBasic = encoding.GetBytes(source.ToCharArray());
                VerifyGetBytes(charArrayResultBasic, 0, charArrayResultBasic.Length, originalBytes, expectedBytes);
            }
            // Use GetBytes(char[], int, int)
            byte[] charArrayResultAdvanced = encoding.GetBytes(source.ToCharArray(), index, count);
            VerifyGetBytes(charArrayResultAdvanced, 0, charArrayResultAdvanced.Length, originalBytes, expectedBytes);

            // Use GetBytes(string, int, int, byte[], int)
            byte[] stringBytes = (byte[])bytes.Clone();
            int stringByteCount = encoding.GetBytes(source, index, count, stringBytes, byteIndex);
            VerifyGetBytes(stringBytes, byteIndex, stringByteCount, originalBytes, expectedBytes);
            Assert.Equal(expectedBytes.Length, stringByteCount);

            // Use GetBytes(char[], int, int, byte[], int)
            byte[] charArrayBytes = (byte[])bytes.Clone();
            int charArrayByteCount = encoding.GetBytes(source.ToCharArray(), index, count, charArrayBytes, byteIndex);
            VerifyGetBytes(charArrayBytes, byteIndex, charArrayByteCount, originalBytes, expectedBytes);
            Assert.Equal(expectedBytes.Length, charArrayByteCount);
        }
    /// <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;
            }
    }
Esempio n. 15
0
 public void Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes, int index, int count, byte[] expected)
 {
     if (index == 0 && count == bytes.Length)
     {
         Assert.Equal(expected, Encoding.Convert(srcEncoding, dstEncoding, bytes));
     }
     Assert.Equal(expected, Encoding.Convert(srcEncoding, dstEncoding, bytes, index, count));
 }
    /// <summary>
    ///     A Stream extension method that reads a stream to the end.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="encoding">The encoding.</param>
    /// <param name="position">The position.</param>
    /// <returns>
    ///     The rest of the stream as a string, from the current position to the end. If the current position is at the
    ///     end of the stream, returns an empty string ("").
    /// </returns>
    public static string ReadToEnd(this Stream @this, Encoding encoding, long position)
    {
        @this.Position = position;

        using (var sr = new StreamReader(@this, encoding))
        {
            return sr.ReadToEnd();
        }
    }
Esempio n. 17
0
 /// <summary>
 /// Create a new reader for the given stream and encoding.
 /// </summary>
 /// <param name="s">The stream to read the CSV from.</param>
 /// <param name="enc">The encoding used.</param>
 public CSVReader(Stream s, Encoding enc)
 {
     this.stream = s;
         if (!s.CanRead)
         {
             throw new CSVReaderException("Could not read the given CSV stream!");
         }
         reader = (enc != null) ? new StreamReader(s, enc) : new StreamReader(s);
 }
 /// <summary>
 ///     A FileInfo extension method that reads the file to the end.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="encoding">The encoding.</param>
 /// <returns>
 ///     The rest of the stream as a string, from the current position to the end. If the current position is at the
 ///     end of the stream, returns an empty string ("").
 /// </returns>
 public static string ReadToEnd(this FileInfo @this, Encoding encoding)
 {
     using (FileStream stream = File.Open(@this.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         using (var reader = new StreamReader(stream, encoding))
         {
             return reader.ReadToEnd();
         }
     }
 }
Esempio n. 19
0
 private void TestEncoding(Encoding enc, int byteCount, int maxByteCount, byte[] bytes)
 {
     Assert.Equal(byteCount, enc.GetByteCount(s_myChars));
     Assert.Equal(maxByteCount, enc.GetMaxByteCount(s_myChars.Length));
     Assert.Equal(enc.GetBytes(s_myChars), bytes);
     Assert.Equal(enc.GetCharCount(bytes), s_myChars.Length);
     Assert.Equal(enc.GetChars(bytes), s_myChars);
     Assert.Equal(enc.GetString(bytes, 0, bytes.Length), s_myString);
     Assert.NotEqual(0, enc.GetHashCode());
 }
Esempio n. 20
0
 public static void GetCharCount(Encoding encoding, byte[] bytes, int index, int count, int expected)
 {
     if (index == 0 && count == bytes.Length)
     {
         // Use GetCharCount(byte[])
         Assert.Equal(expected, encoding.GetCharCount(bytes));
     }
     // Use GetCharCount(byte[], int, int)
     Assert.Equal(expected, encoding.GetCharCount(bytes, index, count));
 }
Esempio n. 21
0
 protected override JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior)
 {
     return new JsonNetResult
     {
         Data = data,
         ContentType = contentType,
         ContentEncoding = contentEncoding,
         JsonRequestBehavior = behavior
     };
 }
Esempio n. 22
0
 /// <summary>
 ///     A string extension method that save the string into a file.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="fileName">Filename of the file.</param>
 /// <param name="append">(Optional) if the text should be appended to file file if it's exists.</param>
 /// <example>
 ///     <code>
 ///           using System;
 ///           using System.IO;
 ///           using Microsoft.VisualStudio.TestTools.UnitTesting;
 ///           using Z.ExtensionMethods;
 ///           
 ///           namespace ExtensionMethods.Examples
 ///           {
 ///               [TestClass]
 ///               public class System_String_SaveAs
 ///               {
 ///                   [TestMethod]
 ///                   public void SaveAs()
 ///                   {
 ///                       var fileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, &quot;Examples_System_String_SaveAs.txt&quot;));
 ///                       string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, &quot;Examples_System_String_SaveAs2.txt&quot;);
 ///           
 ///                       // Type
 ///                       string @this = &quot;Fizz&quot;;
 ///           
 ///                       // Examples
 ///                       @this.SaveAs(filePath); // Save string in a file.
 ///                       @this.SaveAs(fileInfo); // Save string in a file.
 ///                       @this.SaveAs(fileInfo, true); // Append string to existing file.
 ///           
 ///                       // Unit Test
 ///                       Assert.IsTrue(fileInfo.Exists);
 ///                       Assert.IsTrue(new FileInfo(filePath).Exists);
 ///                   }
 ///               }
 ///           }
 ///     </code>
 /// </example>
 public static void SaveAs(this string @this, string fileName, bool append = false, Encoding enc = null)
 {
     var toadd = "";
     if (File.Exists(fileName)) {
         if (append)
             toadd = File.ReadAllText(fileName);
         File.SetAttributes(fileName, FileAttributes.Normal);
         File.Delete(fileName);
     }
     File.WriteAllText(fileName, toadd + @this, enc??Encoding.UTF8);
 }
Esempio n. 23
0
    public static byte[] GetHash(string input, Encoding encoding)
    {
        if (null == input)
            throw new System.ArgumentNullException("input", "Unable to calculate hash over null input data");
        if (null == encoding)
            throw new System.ArgumentNullException("encoding", "Unable to calculate hash over a string without a default encoding. Consider using the GetHash(string) overload to use UTF8 Encoding");

        byte[] target = encoding.GetBytes(input);

        return GetHash(target);
    }
Esempio n. 24
0
	public static async Task<string> ReadStringAsync(this IUVStream<ArraySegment<byte>> stream, Encoding encoding)
	{
		if (encoding == null) {
			throw new ArgumentException("encoding");
		}
		var buffer = await stream.ReadStructAsync();
		if (!buffer.HasValue) {
			return null;
		}
		return encoding.GetString(buffer.Value);
	}
Esempio n. 25
0
	public static async Task<string> ReadStringAsync(this IUVStream stream, Encoding encoding)
	{
		if (encoding == null) {
			throw new ArgumentException("encoding");
		}
		var buffer = await stream.ReadAsync();
		if (buffer == null) {
			return null;
		}
		return encoding.GetString(buffer.Buffer, buffer.Start, buffer.Length);
	}
Esempio n. 26
0
 public static byte[] Serialize(object obj, Encoding encoding)
 {
     Hashtable ht = new Hashtable();
     int hv = 1;
     MemoryStream stream = new MemoryStream();
     stream.Seek(0, SeekOrigin.Begin);
     Serialize(stream, obj, ht, ref hv, encoding);
     byte[] result = stream.ToArray();
     stream.Close();
     return result;
 }
Esempio n. 27
0
        public static void GetBytes(Encoding encoding, string source, int index, int count, byte[] bytes, int byteIndex, int expected)
        {
            // Use GetBytes(string, int, int, byte[], int)
            byte[] stringBytes = (byte[])bytes.Clone();
            int stringResult = encoding.GetBytes(source, index, count, stringBytes, byteIndex);
            Assert.Equal(expected, stringResult);

            // Use GetBytes(char[], int, int, byte[], int)
            byte[] charArrayBytes = (byte[])bytes.Clone();
            int charArrayResult = encoding.GetBytes(source, index, count, charArrayBytes, byteIndex);
            Assert.Equal(expected, charArrayResult);
        }
Esempio n. 28
0
	public static async Task<string> ReadStringAsync(this IUVStream stream, Encoding encoding)
	{
		if (encoding == null) {
			throw new ArgumentException("encoding");
		}
		var buffer = await stream.ReadAsync();
		if (!buffer.HasValue) {
			return null;
		}
		var b = buffer.Value;
		return encoding.GetString(b.Array, b.Offset, b.Count);
	}
Esempio n. 29
0
 public static void GetByteCount(Encoding encoding, string chars, int index, int count, int expected)
 {
     char[] charArray = chars.ToCharArray();
     if (index == 0 && count == chars.Length)
     {
         // Use GetByteCount(string) or GetByteCount(char[])
         Assert.Equal(expected, encoding.GetByteCount(chars));
         Assert.Equal(expected, encoding.GetByteCount(charArray));
     }
     // Use GetByteCount(char[], int, int)
     Assert.Equal(expected, encoding.GetByteCount(charArray, index, count));
 }
Esempio n. 30
0
    public static String ToStringFull(this XDocument That, Encoding Encoding)
    {
        var VersionXmlStream = new MemoryStream();
        var VersionXmlWriter = XmlWriter.Create(VersionXmlStream, new XmlWriterSettings()
        {
            Encoding = Encoding,
            Indent = true,
        });
        That.WriteTo(VersionXmlWriter);
        VersionXmlWriter.Flush();

        return Encoding.GetString(VersionXmlStream.ToArray());
    }
Esempio n. 31
0
            /// <summary>
            /// 解析文件头
            /// </summary>
            private void parseHeader(byte[] header, Encoding encoding)
            {
                // 将转换后的内容写入缓存
                _strHeader.Append(encoding.GetChars(header));

                // 开始解析
                int _index = 0; //存放内容长度

                // 版本号
                byte[] version = getFixedLengthByteArrayFromHeader(header, _index, MyEDFileHeader.FixedLength_Version);
                this.Version = new string(encoding.GetChars(version));
                _index      += FixedLength_Version;

                // 病人ID
                byte[] localPatientIdentification = getFixedLengthByteArrayFromHeader(header, _index, MyEDFileHeader.FixedLength_LocalPatientIdentification);
                _index += MyEDFileHeader.FixedLength_LocalPatientIdentification;

                // 记录ID
                byte[] localRecordingIdentification = getFixedLengthByteArrayFromHeader(header, _index, MyEDFileHeader.FixedLength_LocalRecordingIdentifiaction);
                _index += MyEDFileHeader.FixedLength_LocalRecordingIdentifiaction;

                // 开始日期
                byte[] startDate = getFixedLengthByteArrayFromHeader(header, _index, MyEDFileHeader.FixedLength_StartDateEDF);
                this.StartDateEDF = new string(encoding.GetChars(startDate));
                _index           += EDFHeader.FixedLength_StartDateEDF;

                // 开始时间
                byte[] startTime = getFixedLengthByteArrayFromHeader(header, _index, EDFHeader.FixedLength_StartTimeEDF);
                this.StartTimeEDF = new string(encoding.GetChars(startTime));
                _index           += EDFHeader.FixedLength_StartTimeEDF;

                // 字节数
                byte[] numberOfBytesInHeaderRow = getFixedLengthByteArrayFromHeader(header, _index, EDFHeader.FixedLength_NumberOfBytes);
                this.NumberOfBytes = int.Parse(new string(encoding.GetChars(numberOfBytesInHeaderRow)).Trim());
                _index            += EDFHeader.FixedLength_NumberOfBytes;

                // 专用格式
                byte[] reserved    = getFixedLengthByteArrayFromHeader(header, _index, EDFHeader.FixedLength_Reserved);
                string reservedStr = new string(encoding.GetChars(reserved));

                if (reservedStr.StartsWith(EDFHeader.EDFContinuous) || reservedStr.StartsWith(EDFHeader.EDFDiscontinuous))
                {
                    this._isEDFPlus = true;
                }
                this.Reserved = reservedStr;
                _index       += EDFHeader.FixedLength_Reserved;

                // 记录数
                byte[] numberOfDataRecords = getFixedLengthByteArrayFromHeader(header, _index, EDFHeader.FixedLength_NumberOfDataRecords);
                this.NumberOfDataRecords = (int.Parse(new string(encoding.GetChars(numberOfDataRecords)).Trim()));
                _index += EDFHeader.FixedLength_NumberOfDataRecords;

                // 采样间隔
                byte[] durationOfDataRecord = getFixedLengthByteArrayFromHeader(header, _index, EDFHeader.FixedLength_DuraitonOfDataRecordInSeconds);
                this.DurationOfDataRecordInSeconds = double.Parse(new string(encoding.GetChars(durationOfDataRecord)).Trim());
                _index += EDFHeader.FixedLength_DuraitonOfDataRecordInSeconds;

                // 导联数
                byte[] numberOfSignals = getFixedLengthByteArrayFromHeader(header, _index, EDFHeader.FixedLength_NumberOfSignalsInDataRecord);
                this.NumberOfSignalsInDataRecord = int.Parse(new string(encoding.GetChars(numberOfSignals)).Trim());
                if (this.NumberOfSignalsInDataRecord < 1 || this.NumberOfSignalsInDataRecord > 256)
                {
                    throw new ArgumentException("EDF File has " + this.NumberOfSignalsInDataRecord + " Signals; Number of Signals must be >1 and <=256");
                }
                _index += EDFHeader.FixedLength_NumberOfSignalsInDataRecord;

                this.PatientIdentification   = new EDFLocalPatientIdentification(encoding.GetChars(localPatientIdentification));
                this.RecordingIdentification = new EDFLocalRecordingIdentification(encoding.GetChars(localRecordingIdentification));

                this.StartDateTime = DateTime.ParseExact(this.StartDateEDF + " " + this.StartTimeEDF, "dd.MM.yy HH.mm.ss", System.Globalization.CultureInfo.InvariantCulture);
                //if (this.IsEDFPlus)
                //{
                //    if (!this.StartDateTime.Date.Equals(this.RecordingIdentification.RecordingStartDate))
                //    {
                //        throw new ArgumentException("Header StartDateTime does not equal Header.RecordingIdentification StartDate!");
                //    }
                //    else
                //    {
                this.RecordingIdentification.RecordingStartDate = this.StartDateTime;
                //    }
                //}
            }
        /// <summary>
        /// 将键值对参数集合拼接为Url字符串
        /// </summary>
        /// <param name="paramArray">键值对集合</param>
        /// <param name="encode">转码类型</param>
        /// <returns></returns>
        private static string BuildParam(List <KeyValuePair <string, string> > paramArray, Encoding encode = null)
        {
            string url = "";

            if (encode == null)
            {
                encode = Encoding.UTF8;
            }

            if (paramArray != null && paramArray.Count > 0)
            {
                var parms = "";
                foreach (var item in paramArray)
                {
                    parms += string.Format("{0}={1}&", Encode(item.Key, encode), Encode(item.Value, encode));
                }
                if (parms != "")
                {
                    parms = parms.TrimEnd('&');
                }
                url += parms;
            }
            return(url);
        }
Esempio n. 33
0
 public ICharSequence GetCharSequence(int index, int length, Encoding encoding)
 {
     this.CheckIndex(index, length);
     return(null);
 }
Esempio n. 34
0
 public string ToString(int index, int length, Encoding encoding)
 {
     this.CheckIndex(index, length);
     return(this.ToString(encoding));
 }
Esempio n. 35
0
        private static string ParseMime(Stream reader, string boundary, ref int maxLength, ICollection <Attachment> attachments, Encoding encoding, char?termChar)
        {
            var    maxLengthSpecified = maxLength > 0;
            string data         = null,
                   bounderInner = "--" + boundary,
                   bounderOuter = bounderInner + "--";
            var n    = 0;
            var body = new System.Text.StringBuilder();

            do
            {
                if (maxLengthSpecified && maxLength <= 0)
                {
                    return(body.ToString());
                }
                if (data != null)
                {
                    body.Append(data);
                }
                data = reader.ReadLine(ref maxLength, encoding, termChar);
                n++;
            } while (data != null && !data.StartsWith(bounderInner));

            while (data != null && !data.StartsWith(bounderOuter) && !(maxLengthSpecified && maxLength == 0))
            {
                data = reader.ReadLine(ref maxLength, encoding, termChar);
                if (data == null)
                {
                    break;
                }
                var a = new Attachment {
                    Encoding = encoding
                };

                var part = new StringBuilder();
                // read part header
                while (!data.StartsWith(bounderInner) && data != string.Empty && !(maxLengthSpecified && maxLength == 0))
                {
                    part.AppendLine(data);
                    data = reader.ReadLine(ref maxLength, encoding, termChar);
                    if (data == null)
                    {
                        break;
                    }
                }
                a.RawHeaders = part.ToString();
                // header body

                // check for nested part
                var nestedboundary = a.Headers.GetBoundary();
                if (!string.IsNullOrEmpty(nestedboundary))
                {
                    ParseMime(reader, nestedboundary, ref maxLength, attachments, encoding, termChar);
                    while (!data.StartsWith(bounderInner) && !(maxLengthSpecified && maxLength == 0))
                    {
                        data = reader.ReadLine(ref maxLength, encoding, termChar);
                    }
                }
                else
                {
                    data = reader.ReadLine(ref maxLength, a.Encoding, termChar);
                    if (data == null)
                    {
                        break;
                    }
                    var nestedBody = new StringBuilder();
                    while (!data.StartsWith(bounderInner) && !(maxLengthSpecified && maxLength == 0))
                    {
                        nestedBody.AppendLine(data);
                        data = reader.ReadLine(ref maxLength, a.Encoding, termChar);
                    }
                    a.SetBody(nestedBody.ToString());
                    attachments.Add(a);
                }
            }
            return(body.ToString());
        }
Esempio n. 36
0
            /// <summary>
            /// 解析导联列表
            /// </summary>
            public void parseSignals(byte[] signals, Encoding encoding)
            {
                //将转换后的内容写入缓存
                _strHeader.Append(encoding.GetChars(signals));

                // 解析导联列表。
                this.Signals = new List <EDFSignal>();
                // TODO 各部分字节数应该写成常量
                EDFSignal edf_signal;
                int       _index;

                //遍历33个信道
                for (int i = 0; i < this.NumberOfSignalsInDataRecord; i++)
                {
                    edf_signal = new EDFSignal();

                    _index = 0;

                    // 标签名
                    var _labelLength = 16;



                    byte[] label = getFixedLengthByteArrayFromHeader(signals, (i * _labelLength) + (this.NumberOfSignalsInDataRecord * _index), _labelLength);
                    edf_signal.Label = new string(encoding.GetChars(label)).Trim();
                    _index          += _labelLength;

                    // if (edf_signal.Label.IndexOf("Annotations") > 0) continue;

                    // 序号
                    edf_signal.IndexNumber = (i + 1);

                    // 传感器类型
                    var    _transducerTypeLength = 80;
                    byte[] transducer_type       = getFixedLengthByteArrayFromHeader(signals, (i * _transducerTypeLength) + (this.NumberOfSignalsInDataRecord * _index), _transducerTypeLength);
                    edf_signal.TransducerType = new string(encoding.GetChars(transducer_type));
                    _index += _transducerTypeLength;

                    //
                    var    _physicalDimensionLength = 8;
                    byte[] physical_dimension       = getFixedLengthByteArrayFromHeader(signals, (i * _physicalDimensionLength) + (this.NumberOfSignalsInDataRecord * _index), _physicalDimensionLength);
                    edf_signal.PhysicalDimension = new string(encoding.GetChars(physical_dimension));
                    _index += _physicalDimensionLength;

                    //
                    var    _physicalMinLength = 8;
                    byte[] physical_min       = getFixedLengthByteArrayFromHeader(signals, (i * _physicalMinLength) + (this.NumberOfSignalsInDataRecord * _index), _physicalMinLength);
                    edf_signal.PhysicalMinimum = float.Parse(new string(encoding.GetChars(physical_min)).Trim());
                    _index += _physicalMinLength;

                    //
                    var    _physicalMaxLength = 8;
                    byte[] physical_max       = getFixedLengthByteArrayFromHeader(signals, (i * _physicalMaxLength) + (this.NumberOfSignalsInDataRecord * _index), _physicalMaxLength);
                    edf_signal.PhysicalMaximum = float.Parse(new string(encoding.GetChars(physical_max)).Trim());
                    _index += _physicalMaxLength;

                    //
                    var    _digitalMinLength = 8;
                    byte[] digital_min       = getFixedLengthByteArrayFromHeader(signals, (i * _digitalMinLength) + (this.NumberOfSignalsInDataRecord * _index), _digitalMinLength);
                    edf_signal.DigitalMinimum = float.Parse(new string(encoding.GetChars(digital_min)).Trim());
                    _index += _digitalMinLength;

                    //
                    var    _digitalMaxLength = 8;
                    byte[] digital_max       = getFixedLengthByteArrayFromHeader(signals, (i * _digitalMaxLength) + (this.NumberOfSignalsInDataRecord * _index), _digitalMaxLength);
                    edf_signal.DigitalMaximum = float.Parse(new string(encoding.GetChars(digital_max)).Trim());
                    _index += _digitalMaxLength;

                    //
                    var    _prefilteringLength = 80;
                    byte[] prefiltering        = getFixedLengthByteArrayFromHeader(signals, (i * _prefilteringLength) + (this.NumberOfSignalsInDataRecord * _index), _prefilteringLength);
                    edf_signal.Prefiltering = new string(encoding.GetChars(prefiltering));
                    _index += _prefilteringLength;

                    //
                    var    _samplesEachDatarecordLength = 8;
                    byte[] samples_each_datarecord      = getFixedLengthByteArrayFromHeader(signals, (i * _samplesEachDatarecordLength) + (this.NumberOfSignalsInDataRecord * _index), _samplesEachDatarecordLength);
                    edf_signal.NumberOfSamplesPerDataRecord = int.Parse(new string(encoding.GetChars(samples_each_datarecord)).Trim());
                    _index += _samplesEachDatarecordLength;


                    this.Signals.Add(edf_signal);
                }
            }
Esempio n. 37
0
 public ICharSequence ReadCharSequence(int length, Encoding encoding)
 {
     this.CheckLength(length);
     return(null);
 }
Esempio n. 38
0
 public string ReadString(int length, Encoding encoding)
 {
     this.CheckLength(length);
     return(null);
 }
Esempio n. 39
0
 public int WriteCharSequence(ICharSequence sequence, Encoding encoding) => throw new IndexOutOfRangeException();
Esempio n. 40
0
 public int WriteString(string value, Encoding encoding) => throw new IndexOutOfRangeException();
Esempio n. 41
0
 public string ToString(Encoding encoding) => string.Empty;
Esempio n. 42
0
        /// <summary>
        /// 解析导联表
        /// </summary>
        /// <param name="fs">文件流</param>
        /// <param name="encoding">编码</param>
        /// <summary>
        /// 解析导联列表
        /// </summary>
        private void parseSignals(FileStream fs, Encoding encoding)
        {
            // 读取导联列表
            var buffer = new byte[this._header.NumberOfSignalsInDataRecord * SIGNAL_LENGTH];

            //Debug.WriteLine("NumberOfSignalsInDataRecord长度" + this._header.NumberOfSignalsInDataRecord);

            /*
             * 新建字节数组 buffer  长度为信号数据记录数*信号长度(256)
             */

            fs.Read(buffer, 0, buffer.Length); //从文件里读出数据
                                               //string debugStr = $"导联表数据({buffer.Length}):\n";
                                               //for (var i = 0; i < buffer.Length; i++)
                                               //{
                                               //    debugStr += buffer[i] + " ";
                                               //    if (i % 16 == 0) debugStr += "\n";

            //}
            //Debug.WriteLine(debugStr);



            // 解析导联列表

            String str = "信道解析:\n";

            byte[] myLabel           = new byte[16]; //标签
            byte[] transducerType    = new byte[80]; //传感器类型
            byte[] physicalDimension = new byte[8];  //物理量
            byte[] physicalMinimum   = new byte[8];  //最小物理量
            byte[] physicalMaximum   = new byte[8];  //最大物理量
            byte[] digitalMinimum    = new byte[8];  //最小数字量
            byte[] digitalMaximum    = new byte[8];  //最大数字量
            byte[] prefilterings     = new byte[80]; //滤波
            byte[] samplesDataRecord = new byte[8];  //每条记录的样本
            byte[] reserved          = new byte[32]; //保留位

            List <byte[]> signalInfo = new List <byte[]>();

            signalInfo.Add(myLabel);
            signalInfo.Add(transducerType);
            signalInfo.Add(physicalDimension);
            signalInfo.Add(physicalMinimum);
            signalInfo.Add(physicalMaximum);
            signalInfo.Add(digitalMinimum);
            signalInfo.Add(digitalMaximum);
            signalInfo.Add(prefilterings);
            signalInfo.Add(samplesDataRecord);
            signalInfo.Add(reserved);


            int currentPoint = 0;

            for (int a = 0; a < signalInfo.Count; a++)
            {
                signalInfo[a] = buffer.Skip(currentPoint).Take(signalInfo[a].Length).ToArray();
                currentPoint += signalInfo[a].Length;
            }

            str += $"标签:[ {Ascii2Str(signalInfo[0]).Trim()} ]\n" +
                   $"传感器类型:[{Ascii2Str(signalInfo[1]).Trim()}]\n" +
                   $"物理量:[{Ascii2Str(signalInfo[2]).Trim()}]\n" +
                   $"最小物理量:[{Ascii2Str(signalInfo[3]).Trim()}]\n" +
                   $"最大物理量:[{Ascii2Str(signalInfo[4]).Trim()}]\n" +
                   $"最小数字量:[{Ascii2Str(signalInfo[5]).Trim()}]\n" +
                   $"最大数字量:[{Ascii2Str(signalInfo[6]).Trim()}]\n" +
                   $"滤波:[{Ascii2Str(signalInfo[7]).Trim()}]\n" +
                   $"每条记录的样本:[{Ascii2Str(signalInfo[8]).Trim()}]\n" +
                   $"保留位:[{Ascii2Str(signalInfo[9]).Trim()}]\n";


            MessageBox.Show(str);



            this._header.parseSignals(buffer, encoding);
        }
Esempio n. 43
0
 public int SetString(int index, string value, Encoding encoding) => throw new IndexOutOfRangeException();
Esempio n. 44
0
        /// <summary>
        /// 解析文件头
        /// </summary>
        /// <param name="fs">文件流</param>
        /// <param name="encoding">编码</param>
        private void parseHeader(FileStream fs, Encoding encoding)
        {
            // 读取文件头
            var buffer = new byte[HEADER_LENGTH];


            fs.Read(buffer, 0, buffer.Length);
            String str = "头文件输出:\n";
            int    i   = 0;

            //foreach (byte b in buffer)
            //{
            //    i++;
            //    str += b.ToString() + "  ";
            //    if (i % 16 == 0) str += "\n";

            //}

            byte[]        version                = new byte[8];
            byte[]        patientInfo            = new byte[80];
            byte[]        recordingInfo          = new byte[80];
            byte[]        recordDate             = new byte[8];
            byte[]        recordTime             = new byte[8];
            byte[]        headerRecordByteLength = new byte[8];
            byte[]        reserved               = new byte[44];
            byte[]        dataRecrdNumber        = new byte[8];
            byte[]        durationOfDataRecord   = new byte[8];
            byte[]        signalNumber           = new byte[4];
            List <byte[]> headerInfos            = new List <byte[]>();

            headerInfos.Add(version);
            headerInfos.Add(patientInfo);
            headerInfos.Add(recordingInfo);
            headerInfos.Add(recordDate);
            headerInfos.Add(recordTime);
            headerInfos.Add(headerRecordByteLength);
            headerInfos.Add(reserved);
            headerInfos.Add(dataRecrdNumber);
            headerInfos.Add(durationOfDataRecord);
            headerInfos.Add(signalNumber);



            int currentPosition = 0;

            for (int j = 0; j < headerInfos.Count; j++)
            {
                headerInfos[j]   = buffer.Skip(currentPosition).Take(headerInfos[j].Length).ToArray();
                currentPosition += headerInfos[j].Length;
            }



            str += $"数据版本号:[ {Ascii2Str(headerInfos[0]).Trim()} ]\n" +
                   $"患者信息:[{Ascii2Str(headerInfos[1]).Trim()}]\n" +
                   $"记录信息:[{Ascii2Str(headerInfos[2]).Trim()}]\n" +
                   $"记录日期:[{Ascii2Str(headerInfos[3]).Trim()}]\n" +
                   $"记录时间:[{Ascii2Str(headerInfos[4]).Trim()}]\n" +
                   $"头记录字节长度:[{Ascii2Str(headerInfos[5]).Trim()}]\n" +
                   $"保留区:[{Ascii2Str(headerInfos[6]).Trim()}]\n" +
                   $"数据记录数:[{Ascii2Str(headerInfos[7]).Trim()}]\n" +
                   $"数据记录周期:[{Ascii2Str(headerInfos[8]).Trim()}]\n" +
                   $"信道数量:[{Ascii2Str(headerInfos[9]).Trim()}]\n";


            //for (int currentPosition = 0; currentPosition <buffer.Length ; currentPosition++) {


            //}
            Debug.WriteLine(str);
            MessageBox.Show(str);
            // 解析文件头
            this._header = new MyEDFileHeader(buffer, encoding);
        }
Esempio n. 45
0
        /// <summary>
        /// Convert the specified 'file' into JSON with the Excel DataReader, and save it to the specified 'outputPath'.
        /// </summary>
        /// <param name="options"></param>
        public async Task ConvertWithDataReaderAsync(SourceOptions options)
        {
            var file = new FileInfo(options.File);

            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }
            if (String.IsNullOrWhiteSpace(options.Output))
            {
                throw new ArgumentException("Argument cannot be null, emtpy or whitespace.", nameof(options.Output));
            }
            if (String.IsNullOrWhiteSpace(options.SheetName))
            {
                throw new ConfigurationException("Configuration 'Converter:{Source}:SheetName' cannot be null, emtpy or whitespace.");
            }

            _logger.LogInformation($"Reading file '{file}'.");

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var excelOptions = new ExcelReaderConfiguration()
            {
                FallbackEncoding = Encoding.GetEncoding(1252)
            };

            using var reader = ExcelReaderFactory.CreateReader(file.Open(FileMode.Open, FileAccess.Read), excelOptions);
            var worksheets = reader.AsDataSet();
            var worksheet  = worksheets.Tables[options.SheetName];

            // Get column names.
            var columns = new string[worksheet.Columns.Count];

            var firstRowIsHeader = options.FirstRowIsHeaders;
            var rows             = new List <Dictionary <string, object> >();

            try
            {
                foreach (var wrow in worksheet.Rows)
                {
                    var drow = wrow as DataRow;
                    _logger.LogDebug($"Parsing row '{drow.ItemArray[0]}'");

                    if (firstRowIsHeader)
                    {
                        columns = drow.ItemArray.Select(i => $"{i}").NotNullOrWhiteSpace().ToArray();
                        for (var i = 0; i < columns.Length; i++)
                        {
                            columns[i] = $"{drow.ItemArray[i]}";
                        }
                        firstRowIsHeader = false;
                    }
                    else
                    {
                        // Create a source dictionary containing converted values.
                        var sourceRow = new Dictionary <string, object>();
                        for (var i = 0; i < columns.Length; i++)
                        {
                            var sourceValue = drow.ItemArray[i];

                            var colOptions = options.Columns.ContainsKey(columns[i]) ? options.Columns[columns[i]] : null;
                            var name       = GetName(colOptions, columns[i]);
                            var value      = await GetValueAsync(colOptions, sourceValue, sourceRow);

                            _logger.LogDebug($"Parsing source column '{name}'='{value}'");

                            sourceRow.Add(columns[i], value);

                            _logger.LogDebug($"Parsed source column '{name}'='{value}'");
                        }

                        // Generate output dictionary.
                        var row = new Dictionary <string, object>();
                        for (var i = 0; i < columns.Length; i++)
                        {
                            var colOptions = options.Columns.ContainsKey(columns[i]) ? options.Columns[columns[i]] : null;
                            var name       = GetName(colOptions, columns[i]);
                            var value      = sourceRow[columns[i]];

                            _logger.LogDebug($"Reviewing column '{name}'='{value}'");

                            if (colOptions?.Skip != SkipOption.Never)
                            {
                                if (colOptions?.Skip == SkipOption.Always)
                                {
                                    continue;
                                }
                                if (colOptions?.Skip == SkipOption.AlreadySet && row.ContainsKey(name))
                                {
                                    continue;
                                }
                                if (colOptions?.Skip == SkipOption.Null && (value.GetType().IsDbNull() || value == null))
                                {
                                    continue;
                                }
                                if (colOptions?.Skip == SkipOption.NullOrEmpty && String.IsNullOrEmpty($"{value}"))
                                {
                                    continue;
                                }
                                if (colOptions?.Skip == SkipOption.NullOrWhitespace && String.IsNullOrWhiteSpace($"{value}"))
                                {
                                    continue;
                                }
                            }

                            if (colOptions?.OutputTo?.Any() ?? false)
                            {
                                for (var oi = 0; oi < colOptions.OutputTo.Length; oi++)
                                {
                                    var outputCol = colOptions.OutputTo[oi];
                                    var colExists = row.ContainsKey(outputCol);

                                    if (colOptions.OutputToArray)
                                    {
                                        var newArray = AddToArray(ExtractValue(value, oi), colExists ? row[outputCol] : null);

                                        // Update the output dictionary.
                                        if (colExists)
                                        {
                                            row[outputCol] = newArray;
                                        }
                                        else
                                        {
                                            row.Add(outputCol, newArray);
                                        }
                                    }
                                    else if (colExists)
                                    {
                                        row[outputCol] = ExtractValue(value, oi);
                                    }
                                    else
                                    {
                                        row.Add(outputCol, ExtractValue(value, oi));
                                    }
                                }
                            }
                            else if (colOptions?.OutputToArray == true)
                            {
                                if (row.ContainsKey(name))
                                {
                                    row[name] = AddToArray(value, row[name]);
                                }
                                else
                                {
                                    row.Add(name, AddToArray(value));
                                }
                            }
                            else
                            {
                                row.Add(name, value);
                            }

                            _logger.LogDebug($"Adding column '{name}'='{value}'");
                        }

                        // Post actions can further transform data after a row has been created.
                        // This is useful when one row's data relies on others.
                        if (options.Row?.PostActions?.Any() ?? false)
                        {
                            foreach (var action in options.Row.PostActions)
                            {
                                if (!row.ContainsKey(action.Column))
                                {
                                    throw new ConfigurationException($"Row action configuration column '{action.Column}' does not exist.");
                                }
                                try
                                {
                                    row[action.Column] = await ConvertAsync(row[action.Column], row, action.Converter, action.ConverterArgs);
                                }
                                catch (Exception ex)
                                {
                                    _logger.LogError(ex, $"Unable to perform post action '{action.Column}'.");
                                    throw;
                                }
                            }
                        }
                        rows.Add(row);

                        _logger.LogInformation($"Parsed row '{drow.ItemArray[0]}'");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Fatal error ended converter");
            }

            var json = JsonSerializer.Serialize(rows, _serialzerOptions);

            ExportJsonFile(json, options.Output);
        }
Esempio n. 46
0
        public static byte[] Decompress(byte[] data, Encoding enc, bool littleEndian = true)
        {
            using (BinaryStream i = new BinaryStream(new MemoryStream(data), littleEndian ? ByteConverter.Little : ByteConverter.Big, enc))
            {
                //Header
                byte[] magic = i.ReadBytes(4);
                if (!IsYaz0Compressed(magic))
                {
                    throw new Yaz0Exception("File is not Yaz0-compressed! MagicId = " + Encoding.ASCII.GetString(magic));
                }
                long uncompressedSize = i.ReadUInt32();
                i.Move(8L); //Skip Unknown Long

                //Decoding starts here
                long   dataEnd          = data.Length;
                byte[] uncompressedData = new byte[uncompressedSize];

                long uncompressedPos = 0;

                byte groupHeader = (byte)i.ReadByte();

                while (i.Position < dataEnd && uncompressedPos < uncompressedSize)
                {
                    bool broken = false;
                    for (int c = 0; c < 8; c++)
                    {
                        if (i.Position >= dataEnd || uncompressedPos >= uncompressedSize)
                        {
                            broken = true;
                            break;
                        }

                        if (GetBitFromByte(groupHeader, c))
                        {
                            uncompressedData[uncompressedPos] = (byte)i.ReadByte();
                            uncompressedPos++;
                        }
                        else
                        {
                            byte byte1 = (byte)i.ReadByte();
                            byte byte2 = (byte)i.ReadByte();

                            long src = uncompressedPos - ((byte1 & 0x0F) << 8 | byte2) - 1;

                            byte index = (byte)(byte1 >> 4);

                            if (index != 0)
                            {
                                index = (byte)(i.ReadByte() + 0x12);
                            }
                            else
                            {
                                index += 2;
                            }

                            for (int c1 = 0; c1 < index; c1++)
                            {
                                uncompressedData[uncompressedPos] = uncompressedData[src];
                                uncompressedPos++;
                                src++;
                            }
                        }
                        groupHeader <<= 1;
                    }

                    if (!broken)
                    {
                        if (!(i.Position >= dataEnd || uncompressedPos >= uncompressedSize))
                        {
                            groupHeader = (byte)i.ReadByte();
                        }
                    }
                }
                return(uncompressedData);
            }
        }
Esempio n. 47
0
 /// <summary>
 /// Deserialize object from XML string.
 /// </summary>
 /// <param name="xml">Xml string representing object.</param>
 /// <param name="type">Type of object.</param>
 /// <returns>Object.</returns>
 public static T DeserializeFromXmlString<T>(string xml, Encoding encoding)
 {
     return (T)DeserializeFromXmlString(xml, typeof(T), encoding);
 }
Esempio n. 48
0
 public static byte[] Decompress(String file, Encoding encoding, bool littleEndian = true)
 {
     return(Decompress(File.ReadAllBytes(file), encoding, littleEndian));
 }
Esempio n. 49
0
	public static string convertStringFormat(string str, Encoding source, Encoding target)
	{
		return bytesToString(stringToBytes(str, source), target);
	}
Esempio n. 50
0
 public int SetCharSequence(int index, ICharSequence sequence, Encoding encoding) => throw new IndexOutOfRangeException();
 /// <summary>
 /// Specifies the desired character encoding for the query results.
 /// </summary>
 /// <param name="encoding">An <see cref="Encoding" /> enum.</param>
 /// <returns>
 /// A reference to the current <see cref="IQueryRequest" /> for method chaining.
 /// </returns>
 /// <remarks>
 /// Optional.
 /// </remarks>
 public IQueryRequest Encoding(Encoding encoding)
 {
     _encoding = encoding;
     return(this);
 }
Esempio n. 52
0
 public BinaryWriterExt(Stream output, Encoding encoding) : base(output, encoding)
 {
 }
Esempio n. 53
0
 public string GetString(int index, int length, Encoding encoding)
 {
     this.CheckIndex(index, length);
     return(null);
 }
Esempio n. 54
0
 public BigEndianBinaryReader(Stream input, Encoding encoding)
     : base(input, encoding)
 {
     _charBuffer = null;
     GetInternalBuffer();
 }
Esempio n. 55
0
        public static void Demo3(string url, string indata)
        {
            string          outdata           = "";
            CookieContainer myCookieContainer = new CookieContainer();
            //新建一个CookieContainer来存放Cookie集合

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            //新建一个HttpWebRequest
            request.ContentType     = "application/x-www-form-urlencoded";
            request.ContentLength   = indata.Length;
            request.Method          = "POST";
            request.UserAgent       = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461; .NET CLR 1.0.3705)";
            request.CookieContainer = myCookieContainer;
            //设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainer
            Stream       myRequestStream = request.GetRequestStream();
            StreamWriter myStreamWriter  = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));

            myStreamWriter.Write(indata, 0, indata.Length);
            //把数据写入HttpWebRequest的Request流
            myStreamWriter.Close();
            myRequestStream.Close();
            //关闭打开对象

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            //新建一个HttpWebResponse
            response.Cookies = myCookieContainer.GetCookies(request.RequestUri);
            //获取一个包含url的Cookie集合的CookieCollection
            Stream       myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader   = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));

            outdata = myStreamReader.ReadToEnd();
            //把数据从HttpWebResponse的Response流中读出
            myStreamReader.Close();
            myResponseStream.Close();
            Console.WriteLine(outdata);
            //显示"登录"

            //拿到了Cookie,再进行请求就能直接读取到登录后的内容了
            request = (HttpWebRequest)WebRequest.Create(url);
            request.CookieContainer = myCookieContainer;//*
            //刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证
            response         = (HttpWebResponse)request.GetResponse();
            response.Cookies = myCookieContainer.GetCookies(request.RequestUri);
            myResponseStream = response.GetResponseStream();
            myStreamReader   = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
            outdata          = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            Console.WriteLine(outdata);
            //再次显示"登录"
            //如果把*行注释调,就显示"没有登录"
            request = (HttpWebRequest)WebRequest.Create(url);
            request.CookieContainer = myCookieContainer;//*解析到的CookieContainer
            response         = (HttpWebResponse)request.GetResponse();
            response.Cookies = myCookieContainer.GetCookies(request.RequestUri);
            myResponseStream = response.GetResponseStream();
            myStreamReader   = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
            outdata          = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
        }