public void run() { try { String url = String.format(SUGGESTIONS_URL, URLEncoder.encode(constraint, "UTF-8")); HttpFetcher fetcher = new HttpFetcher(new URI(url), HTTP_QUERY_TIMEOUT); String json = StringUtils.getUTF8String(fetcher.fetch()); if (!isCancelled()) { final List<String> suggestions = readSuggestions((JSONArray) ((JSONArray) JSONValue.parse(json)).get(1)); GUIMediator.safeInvokeLater( new Runnable() { public void run() { Iterator<String> it = suggestions.iterator(); if (it.hasNext()) if (!StringUtils.isNullOrEmpty(input.getText(), true)) { input.showPopup(it); } else input.hidePopup(); } }); } } catch (Throwable e) { // ignore } }
public static MininovaVuzeResponse searchMininovaVuze(String keywords) { String iha = null; try { iha = URLEncoder.encode(keywords, "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } HttpFetcher fetcher = null; try { fetcher = new HttpFetcher(new URI("http://www.mininova.org/vuze.php?search=" + iha), HTTP_TIMEOUT); } catch (URISyntaxException e) { } byte[] jsonBytes = fetcher.fetch(); if (jsonBytes == null) return null; String json = new String(jsonBytes); // fix what seems to be an intentional JSON syntax typo put ther by mininova json = json.replace("\"hash\":", ", \"hash\":"); // Feel the power of reflection JsonEngine engine = new JsonEngine(); MininovaVuzeResponse response = engine.toObject(json, MininovaVuzeResponse.class); return response; }
private void load(final String url) { try { HttpFetcher fetcher = new HttpFetcher(new URI(url)); byte[] jsonBytes = fetcher.fetch(); if (jsonBytes != null) { final SlideList slideList = new JsonEngine().toObject(new String(jsonBytes), SlideList.class); GUIMediator.safeInvokeLater( new Runnable() { public void run() { try { setup(slideList.slides, slideList.randomStart); repaint(); } catch (Exception e) { System.out.println("Failed load of Slide Show:" + url); _slides = null; // nothing happens e.printStackTrace(); } } }); } // System.out.println("Loaded Slide Show for:" + url); } catch (Exception e) { System.out.println("Failed load of Slide Show:" + url); _slides = null; // nothing happens e.printStackTrace(); } }