KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > dfs > StreamConnector


1 package com.knowgate.dfs;
2
3 import java.io.*;
4
5 import com.knowgate.debug.DebugFile;
6 import com.knowgate.misc.ByteStore;
7
8 /**
9  * StreamConnector.java
10  *
11  * Created: Tue Sep 7 14:47:10 1999
12  *
13  * Copyright (C) 2000 Sebastian Schaffert
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28  */

29 /**
30  * Used to write to a OutputStream in a separate Thread to avoid blocking.
31  *
32  * @author Sebastian Schaffert
33  * @version
34  */

35
36 public class StreamConnector extends Thread JavaDoc {
37
38     InputStream in;
39     ByteStore b;
40     int size;
41     boolean ready=false;
42
43     public StreamConnector(InputStream sin, int size) {
44     super();
45     in=sin;
46     this.size=size;
47     b=null;
48     this.start();
49     }
50
51     public void run(String JavaDoc content_type) {
52     b=ByteStore.getBinaryFromIS(in,size,content_type);
53     ready=true;
54     }
55
56     public ByteStore getResult() {
57     while (!ready) {
58         try {
59         sleep(500);
60         if (DebugFile.trace) DebugFile.write(".");
61         } catch(InterruptedException JavaDoc ex) {
62         }
63     }
64     if (DebugFile.trace) DebugFile.write("\n");
65     return b;
66     }
67
68 } // StreamConnector
69
Popular Tags