public int read(InputStream in,int offset,Message overflow) throws IOException {
  if (refCount.get() == 0) {
    throw new IllegalStateException("Modifying a message while in the pool");
  }
  int msgSize=offset < 2 ? 2 : byteBuffer.getShort(0);
  while (offset < msgSize) {
    int max=overflow == null ? Math.max(2,msgSize - offset) : buffer.length - offset;
    int n=in.read(buffer,offset,max);
    if (n < 0) {
      return -1;
    }
    offset+=n;
    if (offset >= msgSize) {
      msgSize=byteBuffer.getShort(0);
    }
  }
  int overflowSize=offset - msgSize;
  if (overflowSize > 0) {
    System.arraycopy(buffer,msgSize,overflow.buffer,0,overflowSize);
  }
  parse();
  return overflowSize;
}

public int read ( InputStream in , int offset , Message overflow ) throws IOException { if ( refCount . get ( ) == 0 ) { throw new IllegalStateException ( "Modifying a message while in the pool" ) ; } int msgSize = offset < 2 ? 2 : byteBuffer . getShort ( 0 ) ; while ( offset < msgSize ) { int max = overflow == null ? Math . max ( 2 , msgSize - offset ) : buffer . length - offset ; int n = in . read ( buffer , offset , max ) ; if ( n < 0 ) { return - 1 ; } offset += n ; if ( offset >= msgSize ) { msgSize = byteBuffer . getShort ( 0 ) ; } } int overflowSize = offset - msgSize ; if ( overflowSize > 0 ) { System . arraycopy ( buffer , msgSize , overflow . buffer , 0 , overflowSize ) ; } parse ( ) ; return overflowSize ; }
returns the number of bytes read into the overflow message . if overflow is null , 0 is returned .
