01: package com.knowgate.dfs;
02:
03: import java.io.*;
04:
05: import com.knowgate.debug.DebugFile;
06: import com.knowgate.misc.ByteStore;
07:
08: /**
09: * 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 {
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 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)
61: DebugFile.write(".");
62: } catch (InterruptedException ex) {
63: }
64: }
65: if (DebugFile.trace)
66: DebugFile.write("\n");
67: return b;
68: }
69:
70: } // StreamConnector
|