1 16 17 package org.apache.catalina.cluster.io; 18 19 20 import java.net.Socket ; 21 import org.apache.catalina.cluster.io.XByteBuffer; 22 23 36 public class Jdk13ObjectReader 37 { 38 private Socket socket; 39 private ListenCallback callback; 40 private XByteBuffer buffer; 41 42 48 public Jdk13ObjectReader( Socket socket, 49 ListenCallback callback, boolean compress) { 50 this.socket = socket; 51 this.callback = callback; 52 this.buffer = new XByteBuffer(compress); 53 } 54 55 56 68 public int append(byte[] data,int off,int len) throws java.io.IOException { 69 boolean result = false; 70 buffer.append(data,off,len); 71 int pkgCnt = 0; 72 boolean pkgExists = buffer.doesPackageExist(); 73 while ( pkgExists ) { 74 byte[] b = buffer.extractPackage(true); 75 callback.messageDataReceived(b); 76 pkgCnt++; 77 pkgExists = buffer.doesPackageExist(); 78 } 79 return pkgCnt; 80 } 81 82 83 89 public int execute() throws java.io.IOException { 90 return append(new byte[0],0,0); 91 } 92 93 100 public int write(byte[] data) 101 throws java.io.IOException { 102 socket.getOutputStream().write(data); 103 return 0; 104 105 } 106 } 107 | Popular Tags |