1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package twcsckernel.projectbase.rmi.socketfactory;
16
17 import java.io.*;
18 import java.net.*;
19
20 /***
21 * Adapts two sockets by sending the data from the output
22 * stream of one to the input stream of the other and
23 * vice versa.
24 *
25 * @author Tim Taylor -- tttaylor@cssassociates.com
26 */
27 public class SocketAdapter {
28 Socket socket1;
29 Socket socket2;
30
31 private class StreamThread extends Thread {
32 InputStream in;
33 OutputStream out;
34
35 StreamThread(InputStream in, OutputStream out) {
36 this.in = in;
37 this.out = out;
38 }
39
40 public void run() {
41 try {
42 for (;;) {
43 int val = in.read();
44 out.write(val);
45 out.flush();
46 if (val == -1) {
47 out.close();
48 in.close();
49 return;
50 }
51 }
52 }
53 catch (IOException e) {
54 }
55 }
56 }
57
58 public SocketAdapter(Socket socket1, Socket socket2) throws IOException {
59 new StreamThread(socket1.getInputStream(), socket2.getOutputStream()).
60 start();
61 new StreamThread(socket2.getInputStream(), socket1.getOutputStream()).
62 start();
63 }
64
65 public void close() {
66 }
67 }