code: public synchronized int read( byte[] b, int off, int len ) throws IOException {
          if( len == 0 ) {
              return 0;
          }
          tot = 0;
  
          while( true ) {
              while( bip > 0 ) {
                  n = in.read( b, off, Math.min( len, bip ));
                  if( n == -1 ) {
                      return tot > 0 ? tot : -1;
                  }
                  tot += n;
                  off += n;
                  len -= n;
                  bip -= n;
                  if( len == 0 ) {
                      return tot;
                  }
              }
  
              switch( SessionServicePacket.readPacketType( in, header, 0 )) {
                  case SessionServicePacket.SESSION_KEEP_ALIVE:
                      break;
                  case SessionServicePacket.SESSION_MESSAGE:
                      bip = SessionServicePacket.readLength( header, 0 );
                      break;
                  case -1:
                      if( tot > 0 ) {
                          return tot;
                      }
                      return -1;
              }
          }
      }
docs: /* This method will not return until len bytes have been read
  or the stream has been closed.