public synchronized JSONArray loadPage ( int i ) { if ( pages == null || pages . get ( i ) == null ) { String url ; if ( path . contains ( "?" ) ) { url = path + "&" ; } else { url = path + "?" ; } //System.out.println(url); JSONObject result = client . get ( url + "per_page=" + perPage + "&page=" + i ) ; //System.out.println(result); if ( result != null && result . names ( ) . size ( ) == 2 && ! result . getJSONObject ( "response_data" ) . isNullObject ( ) ) { responseData = result . getJSONObject ( "response_data" ) ; for ( Object name : result . names ( ) ) { if ( ! "response_data" . equals ( name ) ) { pages . put ( i , result . getJSONArray ( name . toString ( ) ) ) ; } } pages . put ( i , pages . get ( i ) ) ; } else { throw new NotFound ( "The resource you requested is not a collection." ) ; } } return pages . get ( i ) ; }
Requests i th page from UserVoice . Thread - safe and makes one HTTP connection .