1 21 package com.db4o.foundation.network; 22 23 import java.io.*; 24 import java.net.*; 25 26 import com.db4o.*; 27 28 public class YapSocketReal implements YapSocket { 29 30 private Socket _socket; 31 private OutputStream _out; 32 private InputStream _in; 33 private String _hostName; 34 35 public YapSocketReal(String hostName, int port) throws IOException { 36 this(new Socket(hostName, port)); 37 _hostName=hostName; 38 } 39 40 public YapSocketReal(Socket socket) throws IOException { 41 _socket = socket; 42 _out = _socket.getOutputStream(); 43 _in = _socket.getInputStream(); 44 } 45 46 public void close() throws IOException { 47 _socket.close(); 48 } 49 50 public void flush() throws IOException { 51 _out.flush(); 52 } 53 54 public boolean isConnected() { 55 return Platform4.isConnected(_socket); 56 } 57 58 public int read() throws IOException { 59 return _in.read(); 60 } 61 62 public int read(byte[] a_bytes, int a_offset, int a_length) throws IOException { 63 return _in.read(a_bytes, a_offset, a_length); 64 } 65 66 public void setSoTimeout(int timeout) { 67 try { 68 _socket.setSoTimeout(timeout); 69 } catch (SocketException e) { 70 e.printStackTrace(); 71 } 72 } 73 74 public void write(byte[] bytes) throws IOException { 75 _out.write(bytes); 76 } 77 78 public void write(byte[] bytes,int off,int len) throws IOException { 79 _out.write(bytes,off,len); 80 } 81 82 public void write(int i) throws IOException { 83 _out.write(i); 84 } 85 86 public YapSocket openParalellSocket() throws IOException { 87 if(_hostName==null) { 88 throw new IOException("Cannot open parallel socket - invalid state."); 89 } 90 return new YapSocketReal(_hostName,_socket.getPort()); 91 } 92 } 93 | Popular Tags |