public static JSONObject lengthValueRead(InputStream inputStream){
  int length=popLength(inputStream);
  if (length < 0) {
    return null;
  }
 else   if (length > MAX_MESSAGE_SIZE) {
    log.error("Remote party asked us to read " + length + " bytes in a length/value read");
    return null;
  }
  byte[] messageBytes=new byte[length];
  JSONObject recoveredMessage;
  int readByteCount=0;
  try {
    while (readByteCount != length) {
      readByteCount+=inputStream.read(messageBytes,readByteCount,length - readByteCount);
    }
    recoveredMessage=new JSONObject(new String(messageBytes));
  }
 catch (  IOException e) {
    log.error("IOException parsing message bytes: ",e);
    return null;
  }
catch (  JSONException e) {
    log.error("IOException parsing message bytes: ",e);
    return null;
  }
  return recoveredMessage;
}

public static JSONObject lengthValueRead ( InputStream inputStream ) { int length = popLength ( inputStream ) ; if ( length < 0 ) { return null ; } else if ( length > MAX_MESSAGE_SIZE ) { log . error ( "Remote party asked us to read " + length + " bytes in a length/value read" ) ; return null ; } byte [ ] messageBytes = new byte [ length ] ; JSONObject recoveredMessage ; int readByteCount = 0 ; try { while ( readByteCount != length ) { readByteCount += inputStream . read ( messageBytes , readByteCount , length - readByteCount ) ; } recoveredMessage = new JSONObject ( new String ( messageBytes ) ) ; } catch ( IOException e ) { log . error ( "IOException parsing message bytes: " , e ) ; return null ; } catch ( JSONException e ) { log . error ( "IOException parsing message bytes: " , e ) ; return null ; } return recoveredMessage ; }
decode a message of the given type from the input stream and return it . this method is much like a delimited read from google ' s protobufs .
