private StreamInfo parseStream(JSONObject stream,boolean follows){
  if (stream == null) {
    LOGGER.warning("Error parsing stream: Should be JSONObject, not null");
    return null;
  }
  Number viewersTemp;
  String status;
  String game;
  String name;
  String display_name;
  long timeStarted=-1;
  long userId=-1;
  boolean noChannelObject=false;
  try {
    viewersTemp=(Number)stream.get("viewers");
    JSONObject channel=(JSONObject)stream.get("channel");
    if (channel == null) {
      LOGGER.warning("Error parsing StreamInfo: channel null");
      return null;
    }
    status=(String)channel.get("status");
    game=(String)channel.get("game");
    name=(String)channel.get("name");
    display_name=(String)channel.get("display_name");
    userId=JSONUtil.getLong(channel,"_id",-1);
    if (!channel.containsKey("status")) {
      LOGGER.warning("Error parsing StreamInfo: no channel object (" + name + ")");
      noChannelObject=true;
    }
  }
 catch (  ClassCastException ex) {
    LOGGER.warning("Error parsing StreamInfo: unpexected type");
    return null;
  }
  if (name == null || name.isEmpty()) {
    LOGGER.warning("Error parsing StreamInfo: name null or empty");
    return null;
  }
  if (viewersTemp == null) {
    LOGGER.warning("Error parsing StreamInfo: viewercount null (" + name + ")");
    return null;
  }
  try {
    timeStarted=Util.parseTime((String)stream.get("created_at"));
  }
 catch (  java.text.ParseException|NullPointerException|ClassCastException ex) {
    LOGGER.warning("Warning parsing StreamInfo: could not parse created_at (" + ex + ")");
  }
  int viewers=viewersTemp.intValue();
  if (viewers < 0) {
    viewers=0;
    LOGGER.warning("Warning: Viewercount should not be negative, set to 0 (" + name + ").");
  }
  StreamInfo streamInfo=getStreamInfo(name);
  if (noChannelObject) {
    status=streamInfo.getStatus();
    game=streamInfo.getGame();
  }
  streamInfo.setDisplayName(display_name);
  if (streamInfo.setUserId(userId)) {
    api.setUserId(name,userId);
  }
  if (follows) {
    streamInfo.setFollowed(status,game,viewers,timeStarted);
  }
 else {
    streamInfo.set(status,game,viewers,timeStarted);
  }
  return streamInfo;
}

private StreamInfo parseStream ( JSONObject stream , boolean follows ) { if ( stream == null ) { LOGGER . warning ( "Error parsing stream: Should be JSONObject, not null" ) ; return null ; } Number viewersTemp ; String status ; String game ; String name ; String display_name ; long timeStarted = - 1 ; long userId = - 1 ; boolean noChannelObject = false ; try { viewersTemp = ( Number ) stream . get ( "viewers" ) ; JSONObject channel = ( JSONObject ) stream . get ( "channel" ) ; if ( channel == null ) { LOGGER . warning ( "Error parsing StreamInfo: channel null" ) ; return null ; } status = ( String ) channel . get ( "status" ) ; game = ( String ) channel . get ( "game" ) ; name = ( String ) channel . get ( "name" ) ; display_name = ( String ) channel . get ( "display_name" ) ; userId = JSONUtil . getLong ( channel , "_id" , - 1 ) ; if ( ! channel . containsKey ( "status" ) ) { LOGGER . warning ( "Error parsing StreamInfo: no channel object (" + name + ")" ) ; noChannelObject = true ; } } catch ( ClassCastException ex ) { LOGGER . warning ( "Error parsing StreamInfo: unpexected type" ) ; return null ; } if ( name == null || name . isEmpty ( ) ) { LOGGER . warning ( "Error parsing StreamInfo: name null or empty" ) ; return null ; } if ( viewersTemp == null ) { LOGGER . warning ( "Error parsing StreamInfo: viewercount null (" + name + ")" ) ; return null ; } try { timeStarted = Util . parseTime ( ( String ) stream . get ( "created_at" ) ) ; } catch ( java . text . ParseException | NullPointerException | ClassCastException ex ) { LOGGER . warning ( "Warning parsing StreamInfo: could not parse created_at (" + ex + ")" ) ; } int viewers = viewersTemp . intValue ( ) ; if ( viewers < 0 ) { viewers = 0 ; LOGGER . warning ( "Warning: Viewercount should not be negative, set to 0 (" + name + ")." ) ; } StreamInfo streamInfo = getStreamInfo ( name ) ; if ( noChannelObject ) { status = streamInfo . getStatus ( ) ; game = streamInfo . getGame ( ) ; } streamInfo . setDisplayName ( display_name ) ; if ( streamInfo . setUserId ( userId ) ) { api . setUserId ( name , userId ) ; } if ( follows ) { streamInfo . setFollowed ( status , game , viewers , timeStarted ) ; } else { streamInfo . set ( status , game , viewers , timeStarted ) ; } return streamInfo ; }
parse a stream object into a streaminfo object . this gets the name of the stream and gets the appropriate streaminfo object , in which it then loads the other extracted data like status , game , viewercount . this is used for both the response from / streams / : channel / as well as / streams ? channel = [ . . ]
