source: xmlrpcnet/trunk/fuentes/src/util.cs @ 379

Last change on this file since 379 was 379, checked in by hectorgh, 5 years ago

adding project files

File size: 2.7 KB
Line 
1/*
2XML-RPC.NET library
3Copyright (c) 2001-2006, Charles Cook <charlescook@cookcomputing.com>
4
5Permission is hereby granted, free of charge, to any person
6obtaining a copy of this software and associated documentation
7files (the "Software"), to deal in the Software without restriction,
8including without limitation the rights to use, copy, modify, merge,
9publish, distribute, sublicense, and/or sell copies of the Software,
10and to permit persons to whom the Software is furnished to do so,
11subject to the following conditions:
12
13The above copyright notice and this permission notice shall be
14included in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23DEALINGS IN THE SOFTWARE.
24*/
25
26namespace CookComputing.XmlRpc
27{
28  using System;
29  using System.Diagnostics;
30  using System.IO;
31  using System.Text;
32
33  public class Util
34  {
35    // protect constructor because static only class
36    protected Util()
37    {     
38    }
39
40    static public void CopyStream(Stream src, Stream dst)
41    {
42      byte[] buff = new byte[4096];
43      while (true)
44      {
45        int read = src.Read(buff, 0, 4096);
46        if (read == 0)
47          break;
48        dst.Write(buff, 0, read);
49      }
50    }
51   
52    public static Stream StringAsStream(string S)
53    {
54      MemoryStream mstm = new MemoryStream();
55      StreamWriter sw = new StreamWriter(mstm);
56      sw.Write(S);
57      sw.Flush();
58      mstm.Seek(0, SeekOrigin.Begin); 
59      return mstm;
60    }
61
62#if (!COMPACT_FRAMEWORK)
63    public static void TraceStream(Stream stm)
64    {
65      TextReader trdr = new StreamReader(stm, new UTF8Encoding(), true, 4096);
66      String s = trdr.ReadLine();
67      while (s != null)
68      {
69        Trace.WriteLine(s);
70        s = trdr.ReadLine();
71      }
72    }
73
74    public static void DumpStream(Stream stm)
75    {
76      TextReader trdr = new StreamReader(stm);
77       String s = trdr.ReadLine();
78      while (s != null)
79      {
80        Trace.WriteLine(s);
81        s = trdr.ReadLine();
82      }
83    }
84#endif
85
86#if (!COMPACT_FRAMEWORK)
87    public static Guid NewGuid()
88    {
89      return Guid.NewGuid();
90    }
91#else
92    public static Guid NewGuid()
93    {
94      return OpenNETCF.GuidEx.NewGuid();
95    }
96#endif
97  }
98
99}
Note: See TracBrowser for help on using the repository browser.