KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > transport > socket > ClientSocketWrapper


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.transport.socket;
8
9 import java.io.BufferedInputStream JavaDoc;
10 import java.io.BufferedOutputStream JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.InputStream JavaDoc;
13 import java.io.ObjectInputStream JavaDoc;
14 import java.io.ObjectOutputStream JavaDoc;
15 import java.io.OutputStream JavaDoc;
16 import java.net.Socket JavaDoc;
17 import org.jboss.remoting.loading.ObjectInputStreamWithClassLoader;
18
19 /**
20  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
21  */

22 public class ClientSocketWrapper extends SocketWrapper
23 {
24    private ObjectInputStream JavaDoc in;
25    private ObjectOutputStream JavaDoc out;
26
27    public ClientSocketWrapper(Socket JavaDoc socket) throws Exception JavaDoc
28    {
29       super(socket);
30
31       out = createOutputStream(socket);
32       in = createInputStream(socket);
33    }
34
35    protected ObjectInputStream JavaDoc createInputStream(Socket JavaDoc socket)
36          throws IOException JavaDoc
37    {
38       BufferedInputStream JavaDoc bin = new BufferedInputStream JavaDoc(socket.getInputStream());
39       //oin = new ObjectInputStream(bin);
40
ObjectInputStream JavaDoc oin = new ObjectInputStreamWithClassLoader(bin, null);
41       return oin;
42    }
43
44    protected ObjectOutputStream JavaDoc createOutputStream(Socket JavaDoc socket)
45          throws IOException JavaDoc
46    {
47       BufferedOutputStream JavaDoc bout = new BufferedOutputStream JavaDoc(socket.getOutputStream());
48       ObjectOutputStream JavaDoc oout = new ObjectOutputStream JavaDoc(bout);
49       return oout;
50    }
51
52    public OutputStream JavaDoc getOutputStream()
53    {
54       return out;
55    }
56
57    public InputStream JavaDoc getInputStream()
58    {
59       return in;
60    }
61
62    public void checkConnection() throws IOException JavaDoc
63    {
64       // Test to see if socket is alive by send ACK message
65
final byte ACK = 1;
66
67       out.reset();
68       out.writeByte(ACK);
69       out.flush();
70       in.readByte();
71
72    }
73 }
74
75
Popular Tags