public static String readPayload(BufferedReader socketReader,int payloadLength) throws IOException, ReplicatorException {
  if (payloadLength == 0) {
    return "";
  }
 else   if (payloadLength == -1) {
    return null;
  }
  char[] buf=new char[1024];
  StringBuilder payload=new StringBuilder();
  do {
    int bytesRead=socketReader.read(buf,0,buf.length);
    if (bytesRead > 0)     payload.append(new String(buf,0,bytesRead));
  }
 while (payload.length() < payloadLength);
  if (payload.length() != payloadLength) {
    throw new ReplicatorException("Size of received payload is incorrect (expected=" + payloadLength + ", received="+ payload.length()+ "):"+ payload);
  }
  return payload.toString();
}

public static String readPayload ( BufferedReader socketReader , int payloadLength ) throws IOException , ReplicatorException { if ( payloadLength == 0 ) { return "" ; } else if ( payloadLength == - 1 ) { return null ; } char [ ] buf = new char [ 1024 ] ; StringBuilder payload = new StringBuilder ( ) ; do { int bytesRead = socketReader . read ( buf , 0 , buf . length ) ; if ( bytesRead > 0 ) payload . append ( new String ( buf , 0 , bytesRead ) ) ; } while ( payload . length ( ) < payloadLength ) ; if ( payload . length ( ) != payloadLength ) { throw new ReplicatorException ( "Size of received payload is incorrect (expected=" + payloadLength + ", received=" + payload . length ( ) + "):" + payload ) ; } return payload . toString ( ) ; }
reads given size payload from a socket . socket must be open . after reading checks that payload is of expected length .
