Beispiel #1
0
        public void DeserializeXml() {
            var user = Users[0];

            using(var ms = new MemoryStream()) {
                XmlTool.Serialize(user, ms);

                ms.SetStreamPosition();

                var xml = ms.ToText();
                // string xml = StringTool.ToString(ms);

                ms.SetStreamPosition();
                var user2 = XmlTool.Deserialize<User>(ms);

                Assert.AreEqual(user.Id, user2.Id);
                Assert.AreEqual(user.Name, user2.Name);
                Assert.AreEqual(user.Description, user2.Description);

                Assert.IsTrue(user.Equals(user2));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 문자열을 기본 인코딩 방식으로 스트림 (<see cref="System.IO.MemoryStream"/>)의 인스턴스로 변환한다.
        /// </summary>
        /// <param name="s">대상문자열</param>
        /// <returns>기본인코딩 방식으로 Stream을 만든다.</returns>
        public static Stream ToStream(this string s) {
            if(s.IsNull())
                return new MemoryStream();

            var stream = new MemoryStream(s.Length * 2);
            var writer = new StreamWriter(stream);

            writer.Write(s);
            writer.Flush();
            stream.SetStreamPosition();

            return stream;
        }
Beispiel #3
0
        /// <summary>
        /// 문자열을 스트림 (<see cref="System.IO.MemoryStream"/>)의 인스턴스로 변환한다.
        /// </summary>												
        /// <param name="s">대상 문자열</param>
        /// <param name="enc">인코딩 형식</param>
        /// <returns>변환된 Stream 인스턴스 객체</returns>
        /// <remarks>사용하고 난 Stream 인스턴스 객체는 Close()를 호출하여 메모리에서 제거해야 한다.</remarks>
        public static Stream ToStream(this string s, Encoding enc) {
            enc.ShouldNotBeNull("enc");

            if(s.IsNull())
                return new MemoryStream();

            var stream = new MemoryStream(s.Length * 2);
            var writer = new StreamWriter(stream, enc, 1024);

            writer.Write(s);
            writer.Flush();
            stream.SetStreamPosition();

            return stream;
        }
Beispiel #4
0
        public void SerializeTest() {
            var user = Users[0];

            using(var ms = new MemoryStream()) {
                XmlTool.Serialize(user, ms);

                ms.SetStreamPosition();

                var str = ms.ToText();
                Assert.IsNotEmpty(str);

                Assert.IsTrue(str.Contains(user.Id.ToString()));
                Console.WriteLine("Serialized Usre=" + str);
            }
        }
        public void Adaptor_Compress_Decompress_By_Stream_InParallel() {
            var plainStream = PlainText.ToStream();

            Parallel.ForEach(_compressors,
                             compressor => {
                                 var adapter = new CompressAdapter(compressor);

                                 var compressed = adapter.Compress(plainStream);
                                 var recoveryStream = new MemoryStream(compressed.Length * 2);
                                 adapter.Decompress(compressed, recoveryStream);

                                 // 데이터가 써졌으므로, 다시 원 위치로 설정해줘야 합니다.
                                 recoveryStream.SetStreamPosition();

                                 Assert.IsTrue(recoveryStream.Length > 0);
                                 Assert.AreEqual(PlainText, recoveryStream.ToText());
                             });
        }
 public void Stream_SetStreamPosition_Test2()
 {
     using (var ms = new MemoryStream(GetTestBuffer()))
      {
     var position = new StreamPosition(32, null);
     Assert.AreEqual(true, ms.SetStreamPosition(position));
     Assert.AreEqual(32, ms.Position);
      }
 }
 public void Stream_SetStreamPosition_Test1()
 {
     using (var ms = new MemoryStream(GetTestBuffer()))
      {
     var position = new StreamPosition(128, null);
     Assert.AreEqual(false, ms.SetStreamPosition(position));
     Assert.AreEqual(0, ms.Position);
      }
 }