4 // Copyright (C) 2004 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 using System
.Collections
;
32 namespace Beagle
.Util
{
34 public class MultiReader
: TextReader
{
36 Queue readers
= new Queue ();
41 public void Add (TextReader reader
)
43 readers
.Enqueue (reader
);
47 get { return readers.Count; }
50 private TextReader Current
{
52 if (readers
.Count
== 0)
54 return (TextReader
) readers
.Peek ();
60 if (readers
.Count
> 0)
64 public override void Close ()
66 while (Current
!= null) {
72 public override int Peek ()
74 while (Current
!= null) {
75 int peek
= Current
.Peek ();
84 public override int Read ()
86 while (Current
!= null) {
87 int read
= Current
.Read ();
96 public override int Read (char[] buffer
, int index
, int count
)
99 while (Current
!= null && count
> 0) {
100 int actual
= Current
.Read (buffer
, index
+ total
, count
);
109 public override int ReadBlock (char[] buffer
, int index
, int count
)
111 return Read (buffer
, index
, count
);
114 public override string ReadLine ()
116 while (Current
!= null) {
117 string str
= Current
.ReadLine ();
126 public override string ReadToEnd ()
128 StringBuilder all
= new StringBuilder ("");
130 while (Current
!= null) {
131 string str
= Current
.ReadToEnd ();
137 return all
.ToString ();