Mercurial > repos > IBBoard
annotate IO/StreamUtil.cs @ 104:80df73deb8fc
Re #48: Collection equality
* Swap fixed generic types (from auto-generation) for invocation-selected generic types
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 26 Apr 2011 14:57:34 +0000 |
parents | fa8378a30ed2 |
children |
rev | line source |
---|---|
100
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (StreamUtil.cs) is a part of the IBBoard project and is copyright 2011 IBBoard |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System; |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System.IO; |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 namespace IBBoard.IO |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 { |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 public class StreamUtil |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 { |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 public static void CopyStream(Stream fromStream, Stream toStream) |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 byte[] bytes = new byte[8096]; |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 int read; |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 while ((read = fromStream.Read(bytes, 0, bytes.Length)) > 0) |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 { |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 toStream.Write(bytes, 0, read); |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 } |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 } |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 public static byte[] ToBytes(Stream fromStream) |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 { |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 MemoryStream toStream = new MemoryStream(); |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 CopyStream(fromStream, toStream); |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 return toStream.ToArray(); |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 } |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 } |
fa8378a30ed2
* Add some Stream handling utilities
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 } |