Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: Freenet/support/Splitter.java


1   package Freenet.support;
2   
3   import java.io.*;
4   import java.util.*;
5   
6   public class Splitter extends OutputStream implements Runnable
7   {
8     private Vector outputs=new Vector();
9     private Vector writers=new Vector();
10    InputStream source;
11  
12    public Splitter()
13    {
14      source=null;
15    }
16  
17    public Splitter(InputStream in)
18    {
19      source=in;
20    }
21  
22    public void split()
23    {
24      int c;
25  
26      if(source!=null)
27        try
28        {
29          do
30          {
31            c=source.read();
32            if(c!=-1)
33              write(c);
34          }
35          while(c!=-1);
36        }
37        catch(IOException e) {}
38    }
39  
40      public void run() {
41    split();
42      }
43  
44    public void addoutput(OutputStream out)
45    {
46      outputs.addElement(out);
47    }
48  
49    public void addwriter(Writer w)
50    {
51      writers.addElement(w);
52    }
53  
54    public void write(int c)
55    {
56      int len, x;
57      OutputStream current;
58      Writer cw;
59  
60      len=outputs.size();
61      if(len!=0)
62      {
63        x=0;
64        while(x<len)
65        {
66          current=(OutputStream)outputs.elementAt(x);
67          try { current.write(c); x=x+1;}
68          catch(IOException e) { outputs.removeElementAt(x); len=len-1;}
69        }
70      }
71  
72      len=writers.size();
73      if(len!=0)
74      {
75        x=0;
76        while(x<len)
77        {
78          cw=(Writer)writers.elementAt(x);
79          try { cw.write(c); x=x+1;}
80          catch(IOException e) { writers.removeElementAt(x); len=len-1;}
81        }
82      }
83    }
84  }
85