KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > util > JReciever


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * 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
38 public class JReciever implements Runnable JavaDoc
39 {
40     private DataInputStream in;
41     private Thread JavaDoc reciever;
42     private byte[] buf = new byte[4048];
43
44     public JReciever(DataInputStream in)
45     {
46         this.in = in;
47         reciever = new Thread JavaDoc(this);
48         reciever.start();
49     }
50
51     public void run()
52     {
53         try
54         {
55             while(true)
56             {
57                 int cnt = in.read(buf);
58
59                 if(cnt == -1)
60                 {
61                     RawConnection.output.append(">>> Connection closed...");
62
63                     LocalIO.pause(100);
64
65                     JScrollBar bar = RawConnection.outputPane.getVerticalScrollBar();
66                     bar.setValue(bar.getMaximum());
67
68                     in.close();
69
70                     return;
71                 }
72                 else
73                 {
74                     String JavaDoc tmp = new String JavaDoc(buf);
75                     tmp = tmp.substring(0, cnt);
76
77                     RawConnection.output.append(tmp);
78                     LocalIO.pause(100);
79
80                     JScrollBar bar = RawConnection.outputPane.getVerticalScrollBar();
81                     bar.setValue(bar.getMaximum());
82
83                     LocalIO.pause(400);
84                 }
85             }
86         }
87         catch(Exception JavaDoc ex)
88         {
89             ex.printStackTrace();
90         }
91     }
92
93     public void reset(DataInputStream in)
94     {
95         reciever.destroy();
96         this.in = in;
97         reciever = new Thread JavaDoc(this);
98         reciever.start();
99     }
100 }
101
Popular Tags