01: /*
02: * This program is free software; you can redistribute it and/or
03: * modify it under the terms of the GNU General Public License
04: * as published by the Free Software Foundation; either version 2
05: * of the License, or (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU General Public License for more details.
11:
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package net.sf.jftp.util;
17:
18: import net.sf.jftp.*;
19: import net.sf.jftp.config.*;
20: import net.sf.jftp.gui.framework.*;
21: import net.sf.jftp.net.*;
22: import net.sf.jftp.system.LocalIO;
23: import net.sf.jftp.util.*;
24:
25: import java.awt.*;
26: import java.awt.event.*;
27:
28: import java.io.*;
29:
30: import java.net.*;
31:
32: import java.util.*;
33:
34: import javax.swing.*;
35: import javax.swing.event.*;
36:
37: public class JReciever implements Runnable {
38: private DataInputStream in;
39: private Thread reciever;
40: private byte[] buf = new byte[4048];
41:
42: public JReciever(DataInputStream in) {
43: this .in = in;
44: reciever = new Thread(this );
45: reciever.start();
46: }
47:
48: public void run() {
49: try {
50: while (true) {
51: int cnt = in.read(buf);
52:
53: if (cnt == -1) {
54: RawConnection.output
55: .append(">>> Connection closed...");
56:
57: LocalIO.pause(100);
58:
59: JScrollBar bar = RawConnection.outputPane
60: .getVerticalScrollBar();
61: bar.setValue(bar.getMaximum());
62:
63: in.close();
64:
65: return;
66: } else {
67: String tmp = new String(buf);
68: tmp = tmp.substring(0, cnt);
69:
70: RawConnection.output.append(tmp);
71: LocalIO.pause(100);
72:
73: JScrollBar bar = RawConnection.outputPane
74: .getVerticalScrollBar();
75: bar.setValue(bar.getMaximum());
76:
77: LocalIO.pause(400);
78: }
79: }
80: } catch (Exception ex) {
81: ex.printStackTrace();
82: }
83: }
84:
85: public void reset(DataInputStream in) {
86: reciever.destroy();
87: this .in = in;
88: reciever = new Thread(this);
89: reciever.start();
90: }
91: }
|