@@ -0,0 +1,1781 @@
+/**%0A * %0A */%0Apackage com.trendrr.oss.networking;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.nio.ByteBuffer;%0A%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A%0Aimport com.trendrr.oss.exceptions.TrendrrDisconnectedException;%0Aimport com.trendrr.oss.exceptions.TrendrrException;%0A%0A%0A/**%0A * @author Dustin Norlander%0A * @created Apr 5, 2012%0A * %0A */%0Aclass ByteReadFullyCallback implements ByteReadCallback %7B%0A%0A%09protected static Log log = LogFactory.getLog(ByteReadFullyCallback.class);%0A%09%0A%09private ByteReadCallback callback;%0A%09private ByteArrayOutputStream baos; %0A%09private SocketChannelWrapper socket;%0A%09%0A%09static final int NUMBYTES = 1024;%0A%09%0A%09public ByteReadFullyCallback(SocketChannelWrapper socket, ByteReadCallback callback) %7B%0A%09%09this.callback = callback;%0A%09%09this.baos = new ByteArrayOutputStream();%0A%09%09this.socket = socket;%0A%09%09this.socket.setCloseListener(this);%0A%09%7D%0A%0A%09/* (non-Javadoc)%0A%09 * @see com.trendrr.oss.networking.ChannelCallback#onError(com.trendrr.oss.exceptions.TrendrrException)%0A%09 */%0A%09@Override%0A%09public void onError(TrendrrException ex) %7B%0A%09%09if (ex instanceof TrendrrDisconnectedException) %7B%0A%09%09%09//eof%0A%09%09%09byte%5B%5D retVal = baos.toByteArray();%0A%09%09%09try %7B%0A%09%09%09%09baos.close();%0A%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09log.error(%22caught%22, e);%0A%09%09%09%7D%0A%09%09%09this.callback.byteResult(retVal);%0A%09%09%09return;%0A%09%09%7D%0A%09%09this.callback.onError(ex);%0A%09%7D%0A%0A%09/* (non-Javadoc)%0A%09 * @see com.trendrr.oss.networking.ByteReadCallback#byteResult(byte%5B%5D)%0A%09 */%0A%09@Override%0A%09public void byteResult(byte%5B%5D result) %7B%0A%09%09try %7B%0A//%09%09%09System.out.println(%22READ: %22 + result.length);%0A%09%09%09this.baos.write(result);%0A%09%09%09if (!this.socket.hasReads())%0A%09%09%09%09this.socket.readBytes(NUMBYTES, this);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09this.callback.onError(new TrendrrException(e));%0A%09%09%7D%0A%09%7D%0A%09%0A%7D%0A

add readfully callback, internally used to readFully from a socketchannel