1 7 package org.jboss.remoting.transport.socket; 8 9 import java.io.IOException ; 10 import java.io.InputStream ; 11 import java.io.OutputStream ; 12 import java.net.Socket ; 13 import java.net.SocketException ; 14 15 18 public abstract class SocketWrapper 19 { 20 private Socket socket; 21 private int timeout; 22 23 public SocketWrapper(Socket socket) 24 { 25 this.socket = socket; 26 } 27 28 public abstract OutputStream getOutputStream(); 29 30 public abstract InputStream getInputStream(); 31 32 public abstract void checkConnection() throws IOException ; 33 34 public void setTimeout(int timeout) throws SocketException 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 50 { 51 if(socket != null) 52 { 53 socket.close(); 54 } 55 } 56 57 protected Socket 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 ignored) 71 { 72 } 73 } 74 } 75 76 } | Popular Tags |