1 | /* |
---|
2 | XML-RPC.NET library |
---|
3 | Copyright (c) 2001-2006, Charles Cook <charlescook@cookcomputing.com> |
---|
4 | |
---|
5 | Permission is hereby granted, free of charge, to any person |
---|
6 | obtaining a copy of this software and associated documentation |
---|
7 | files (the "Software"), to deal in the Software without restriction, |
---|
8 | including without limitation the rights to use, copy, modify, merge, |
---|
9 | publish, distribute, sublicense, and/or sell copies of the Software, |
---|
10 | and to permit persons to whom the Software is furnished to do so, |
---|
11 | subject to the following conditions: |
---|
12 | |
---|
13 | The above copyright notice and this permission notice shall be |
---|
14 | included in all copies or substantial portions of the Software. |
---|
15 | |
---|
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
---|
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
---|
18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
---|
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
---|
20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
---|
21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
23 | DEALINGS IN THE SOFTWARE. |
---|
24 | */ |
---|
25 | |
---|
26 | namespace 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 | } |
---|