private int parseStreams(String json,Set<StreamInfo> streamInfos){
  try {
    JSONParser parser=new JSONParser();
    JSONArray streamsArray;
    try {
      JSONObject root=(JSONObject)parser.parse(json);
      streamsArray=(JSONArray)root.get("streams");
    }
 catch (    ClassCastException ex) {
      LOGGER.warning("Error parsing streams: unexpected type");
      streamsRequestError(streamInfos);
      return -1;
    }
    if (streamsArray == null) {
      LOGGER.warning("Error parsing streams: streams array not found");
      streamsRequestError(streamInfos);
      return -1;
    }
    for (    Object obj : streamsArray) {
      if (obj instanceof JSONObject) {
        StreamInfo parsedInfo=parseStream((JSONObject)obj,streamInfos == null);
        if (parsedInfo == null) {
          LOGGER.warning("Error parsing stream " + (JSONObject)obj);
        }
        if (streamInfos != null) {
          streamInfos.remove(parsedInfo);
        }
      }
 else {
        LOGGER.warning("Element in array wasn't JSONObject " + obj);
      }
    }
    if (streamInfos != null) {
      for (      StreamInfo info : streamInfos) {
        info.setOffline();
      }
    }
    return streamsArray.size();
  }
 catch (  ParseException ex) {
    LOGGER.warning("Error parsing streams info: " + ex.getLocalizedMessage());
    streamsRequestError(streamInfos);
    return -1;
  }
}

private int parseStreams ( String json , Set < StreamInfo > streamInfos ) { try { JSONParser parser = new JSONParser ( ) ; JSONArray streamsArray ; try { JSONObject root = ( JSONObject ) parser . parse ( json ) ; streamsArray = ( JSONArray ) root . get ( "streams" ) ; } catch ( ClassCastException ex ) { LOGGER . warning ( "Error parsing streams: unexpected type" ) ; streamsRequestError ( streamInfos ) ; return - 1 ; } if ( streamsArray == null ) { LOGGER . warning ( "Error parsing streams: streams array not found" ) ; streamsRequestError ( streamInfos ) ; return - 1 ; } for ( Object obj : streamsArray ) { if ( obj instanceof JSONObject ) { StreamInfo parsedInfo = parseStream ( ( JSONObject ) obj , streamInfos == null ) ; if ( parsedInfo == null ) { LOGGER . warning ( "Error parsing stream " + ( JSONObject ) obj ) ; } if ( streamInfos != null ) { streamInfos . remove ( parsedInfo ) ; } } else { LOGGER . warning ( "Element in array wasn't JSONObject " + obj ) ; } } if ( streamInfos != null ) { for ( StreamInfo info : streamInfos ) { info . setOffline ( ) ; } } return streamsArray . size ( ) ; } catch ( ParseException ex ) { LOGGER . warning ( "Error parsing streams info: " + ex . getLocalizedMessage ( ) ) ; streamsRequestError ( streamInfos ) ; return - 1 ; } }
parses a list of stream objects . goes through all stream objects and parses them ( which also means it updates the appropriate streaminfo objects in the process ) , then sets all remaining streams that were expected in this response to offline . this parses the response to / streams ? channel = [ . . ]
