1 21 package com.db4o.foundation.network; 22 23 import java.io.*; 24 25 28 public class YapSocketFake implements YapSocket { 29 30 private final YapSocketFakeServer _server; 31 32 private YapSocketFake _affiliate; 33 private ByteBuffer4 _uploadBuffer; 34 private ByteBuffer4 _downloadBuffer; 35 36 public YapSocketFake(YapSocketFakeServer a_server, int timeout) { 37 _server = a_server; 38 _uploadBuffer = new ByteBuffer4(timeout); 39 _downloadBuffer = new ByteBuffer4(timeout); 40 } 41 42 public YapSocketFake(YapSocketFakeServer a_server, int timeout, YapSocketFake affiliate) { 43 this(a_server, timeout); 44 _affiliate = affiliate; 45 affiliate._affiliate = this; 46 _downloadBuffer = affiliate._uploadBuffer; 47 _uploadBuffer = affiliate._downloadBuffer; 48 } 49 50 public void close() throws IOException { 51 if (_affiliate != null) { 52 YapSocketFake temp = _affiliate; 53 _affiliate = null; 54 temp.close(); 55 } 56 _affiliate = null; 57 } 58 59 public void flush() { 60 } 62 63 public boolean isConnected() { 64 return _affiliate != null; 65 } 66 67 public int read() throws IOException { 68 return _downloadBuffer.read(); 69 } 70 71 public int read(byte[] a_bytes, int a_offset, int a_length) throws IOException { 72 return _downloadBuffer.read(a_bytes, a_offset, a_length); 73 } 74 75 public void setSoTimeout(int a_timeout) { 76 _uploadBuffer.setTimeout(a_timeout); 77 _downloadBuffer.setTimeout(a_timeout); 78 } 79 80 public void write(byte[] bytes) throws IOException { 81 _uploadBuffer.write(bytes); 82 } 83 84 public void write(byte[] bytes,int off,int len) throws IOException { 85 _uploadBuffer.write(bytes, off, len); 86 } 87 88 public void write(int i) throws IOException { 89 _uploadBuffer.write(i); 90 } 91 92 public YapSocket openParalellSocket() throws IOException { 93 return _server.openClientSocket(); 94 } 95 } 96 | Popular Tags |