KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
10 import java.io.InputStream JavaDoc;
11 import java.io.OutputStream JavaDoc;
12 import java.net.Socket JavaDoc;
13 import java.net.SocketException JavaDoc;
14
15 /**
16  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
17  */

18 public abstract class SocketWrapper
19 {
20    private Socket JavaDoc socket;
21    private int timeout;
22
23    public SocketWrapper(Socket JavaDoc socket)
24    {
25       this.socket = socket;
26    }
27
28    public abstract OutputStream JavaDoc getOutputStream();
29
30    public abstract InputStream JavaDoc getInputStream();
31
32    public abstract void checkConnection() throws IOException JavaDoc;
33
34    public void setTimeout(int timeout) throws SocketException JavaDoc
35    {
36       this.timeout = timeout;
37       if(socket != null)
38       {
39          socket.setSoTimeout(timeout);
40       }
41    }
42
43    public int getTimeout()
44    {
45       return timeout;
46    }
47
48
49    public void close() throws IOException JavaDoc
50    {
51       if(socket != null)
52       {
53          socket.close();
54       }
55    }
56
57    protected Socket JavaDoc getSocket()
58    {
59       return socket;
60    }
61
62    protected void finalize()
63    {
64       if(socket != null)
65       {
66          try
67          {
68             socket.close();
69          }
70          catch(Exception JavaDoc ignored)
71          {
72          }
73       }
74    }
75
76 }
Popular Tags